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?

 Accepted Answer

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);

More Answers (1)

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.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Asked:

Ry
on 17 Feb 2014

Answered:

on 17 Feb 2014

Community Treasure Hunt

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

Start Hunting!