while inside a loop.
Afficher commentaires plus anciens
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.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Mathematics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!