how can I let the string variable change in a loop

2 views (last 30 days)
Dear fellows,
I am trying to plot the scatter for a set of vectors. My secource file pf.mat is a 65*154 matrix. I want to plot two columns each time so I am writing a loop (i=1:77)from 1 to 77. In each loop, after plot the vectors, I would to save the image as the number of the i. My questions is how do I name the image then it can change as th loop goes on? My current code only can save the image as the letter i, but not the actual number of i. Here is my code
if true
% load pf
for i=1:77
scatter(pf(:,(2*i-1)),pf(:,2*i),'.')
hold on
plot([0,100],[100,0])
h(i)=scatter(pf(:,(2*i-1)),pf(:,2*i),'.');
saveas(h(i),'i', 'pdf')
end end

Accepted Answer

Iain
Iain on 19 Jun 2013
try using num2str(i) instead of 'i'.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!