to calculate minimum or maximum value of dataset
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
2 commentaires
Image Analyst
le 7 Sep 2013
He says what x is, but more importantly, what is u1,u2,u3,u4, & y ??? That's not standard MATLAB code. Do you want each of those to be the 2D array x_train?
Réponse acceptée
Image Analyst
le 7 Sep 2013
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
Plus de réponses (1)
Andrei Bobrov
le 7 Sep 2013
Modifié(e) : Andrei Bobrov
le 7 Sep 2013
x_s = sortrows(x_train,[5,1]);
c = accumarray(x_s(:,5),x_s(:,1),[],@(x){x([1,end])});
out = cat(2,c{:});
or
c = accumarray(x_train(:,5),x_train(:,1),[],@(x){[min(x) max(x)]});
out = cat(1,c{:});
0 commentaires
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!