MATLAB: Extracting an element in a vector

extractingvectors

there is a vector like A=[a b c d] and these a b c d are the numbers which I dont know the values. If I write max(A), then I find the max value element of this vector;and writing min(A), I can find the min element of this vector. but I want to create a new vector taking the two values of this A vector except these two max and min. I wanna take the other two element. so,how can i do this?
thanks so much.

Best Answer

[~,ii] = max(A);
[~,ii(2)] = min(A);
out = A(setdiff(1:numel(A),ii));
other way
[~,ii] = sort(A);
out = A(sort(ii(2:end-1)));
more way
out = A(A ~= max(A) & A ~= min(A));