Can I get outputs numbered each time it goes through a loop?

I have a "for" loop that runs through my data and gives outputs nicely. It looks like....
a=[334.480, 334.481, 334.486, 334.485, 334.480, 334.480, 334.478, 334.479, 334.479, 334.483];
b=[341.013, 341.017, 341.017, 341.017, 341.017, 341.025, 341.020, 341.021, 341.026, 341.025];
>> for k=1:10-5+1
c=a(k:k+5)
d=b(k:k+5)
m1=mean(a)
m2=mean(b)
co=corrcoef(a,b)
va=varr(a,b)
end
As it runs the outputs are labeled c, d, m1, m2, co, and va each time. Is there a way to have matlab tell me this is the 3rd time this has been output? Do I have to ask matlab after it has run, or can I use code to have matlab tell me before I ask?

 Réponse acceptée

Just put k on its own line,
k
which will spit the value of k out to the command window, or else add this line:
fprintf('k = %d\n', k);

Plus de réponses (1)

Mischa Kim
Mischa Kim le 17 Fév 2014
Modifié(e) : Mischa Kim le 17 Fév 2014
Ry, you could add
disp(['Loop iteration: ', num2str(k)]);
just before the end of the loop. It displays some text and the loop index k.

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by