필터 지우기
필터 지우기

to calculate minimum or maximum value of dataset

조회 수: 4 (최근 30일)
Parul
Parul 2013년 9월 7일
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
Azzi Abdelmalek
Azzi Abdelmalek 2013년 9월 7일
What is x?
Image Analyst
Image Analyst 2013년 9월 7일
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?

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2013년 9월 7일
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

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2013년 9월 7일
편집: Andrei Bobrov 2013년 9월 7일
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{:});

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by