MATLAB: To calculate minimum or maximum value of dataset

maximumminimum

I want to calculate minimum or maximum value of three divisions of set as shown by separation line or described by diff value of fifth coloumn. please help
x_train= [5.1 3.5 1.4 0.2 1
4.9 3.0 1.4 0.2 1
4.7 3.2 1.3 0.2 1
%...........................
6.5 2.8 4.6 1.5 2
5.7 2.8 4.5 1.3 2
6.3 3.3 4.7 1.6 2
4.9 2.4 3.3 1.0 2
%..............................
7.3 2.9 6.3 1.8 3
6.7 2.5 5.8 1.8 3
7.2 3.6 6.1 2.5 3
6.5 3.2 5.1 2.0 3]
[u1,u2,u3,u4,y]=x_train;
x=[u1 u2 u3 u4 y];
for k=1:3
while x(:,5)==k
w_low(k)=min(x(:,1));
w_up(k)=max(x(:,1));
end
end

Best Answer

Perhaps you mean this:
x_train= [5.1 3.5 1.4 0.2 1
4.9 3.0 1.4 0.2 1
4.7 3.2 1.3 0.2 1
%...........................
6.5 2.8 4.6 1.5 2
5.7 2.8 4.5 1.3 2
6.3 3.3 4.7 1.6 2
4.9 2.4 3.3 1.0 2
%..............................
7.3 2.9 6.3 1.8 3
6.7 2.5 5.8 1.8 3
7.2 3.6 6.1 2.5 3
6.5 3.2 5.1 2.0 3]
% Find unique numbers in column 5.
possibleValues = unique(int32(x_train(:, 5)))
counter = 1;
for k=1:length(possibleValues)
thisValue = possibleValues(k);
fprintf('\nFor column #5 = %d\n', thisValue);
% Get all rows with this number in column 5
matchingRows = x_train(:,5) == thisValue
% Find the min and max in column 1 of that chunk.
w_low(counter)=min(x_train(matchingRows,1));
w_up(counter)=max(x_train(matchingRows,1));
counter = counter + 1;
end
% Display results in command window
fprintf('\nFinal Results:\n');
w_low
w_up
In the command window:
Final Results:
w_low = 4.7 4.9 6.5
w_up = 5.1 6.5 7.3