while inside a loop.
이전 댓글 표시
load cities.mat;
temp_ratings = sort(ratings,'descend');
for j=1:9
i=0;
temp_vec=zeros(1,9);
while temp_vec==zeros(1,9)
i=i+1
if temp_ratings(i+1)~=temp_ratings(i+2)
temp_vec=temp_ratings(i+2);
end
end;
end;
This is a code that i'm trying to write for homework. I need to find the 2nd Highest number in each column. I made easier codes, even without loops for this one, but i'm trying to make it a lil bit more sophisticated. The thing is that in some of the columns sometimes there're more than 1 elements that are presenting the highest number, so I need to take that in account.
This is the only direction that I'm trying to do, so i'm not looking too much for a new command or something more than I'm using here. Anyway - The problem with my code that it does what I want but only for the first column! I mean that the while command is working and after it gets the 'if' and stops the loop (of 'for' command).
What am i missing here? Thanks, Eran.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Mathematics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!