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!