필터 지우기
필터 지우기

choose the 3 first lowest number in the cell after it sorted

조회 수: 2 (최근 30일)
baby
baby 2013년 1월 21일
hello all,,
i wanna ask u about how to choose the 3 first lowest number in that cell after it sorted
this is my code
a= input ('Input Number of Data :');
for c=1:a
int2 = ['Input The First Score - ',num2str(c),' :'];
int3 = ['Input The Second Score - ',num2str(c),' :'];
str = ['Input Category ke - ',num2str(c),' :'];
b(c,1) = input(int2);
b(c,2) = input(int3);
f{c,4} = input(str,'s');
end;
for d = 1 : 1
int4= ['Input The First Data :'];
int5 = ['Input The Second Data :'];
e(d,1) = input(int4);
e(d,2) = input(int5);
end;
length = ( b(:,1) - e(1,1)).^2 + (b(:,2) - e(1,2)).^2
for i = 1:size(b,1)
for j = 1:2
f{i,j} = b(i,j);
end;
end
[key, index] = sort([f{:, 2}]);
sorted_f = f(index, :);
can anyone help me?
please

채택된 답변

Jan
Jan 2013년 1월 21일
편집: Jan 2013년 1월 21일
sorted_f(end-2:end, :)
It is surprising, that Thorsten's [f{end-2:end, :}] replies 3 elements only and a column vector.
  댓글 수: 1
baby
baby 2013년 1월 21일
편집: baby 2013년 1월 21일
wait,,it's not working
when i test with other data the result is wrong
sorted_f =
[3] [4] [ 9] 'low'
[1] [4] [13] 'low'
[7] [7] [16] 'high'
[7] [4] [25] 'high'
this is sorted f's result
and this is wrong minimal value of ur command
[1] [4] [13] 'low'
[7] [7] [16] 'high'
[7] [4] [25] 'high'
the true result is
[3] [4] [ 9] 'low'
[1] [4] [13] 'low'
[7] [7] [16] 'high'
as u see the command not give the true result
it just select three data from bottom
can u fix it?

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

추가 답변 (2개)

Thorsten
Thorsten 2013년 1월 21일
[f{end-2:end, :}]

Thorsten
Thorsten 2013년 1월 21일
reshape({f{end-2:end,:}}, [3 3])
  댓글 수: 1
baby
baby 2013년 1월 21일
편집: baby 2013년 1월 21일
Thorsten, thx u so much for ur help :)

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by