Why doesn't my loop code loop?

Here is the code I'm trying to use to generate multiple .jpg images by looping.
for a=11:12:143
data1=data1(:,date1(a:a+11,:));
data2=data2(:,date2(a:a+11,:));
R = corr2(data1,data2);
R_squared = R^2;
figure
scatter(data1,data2)
ylabel('CF (unitless)')
xlabel('AOD')
title('Cloud Fraction Vs Aerosol Optical Depth (Ocean only, -10 <= lat <= 7, 1 deg. Monthly Resolution)')
text(4.5,1, ['R^2 = ' num2str(R_squared)])
axis([0 5 0 1])
grid on
year = a+1990;
print('-djpeg','-r300',sprintf('CF vs. AOD-%d.jpg',year))
end
But instead of 11 images like I'm supposed to get (if you divide distance/step size = (154-11)/11) I only get one, the loop isn't looping. Can anyone help me out here, tell me why??
Thanks!

5 件のコメント

per isakson
per isakson 2013 年 5 月 9 日
編集済み: per isakson 2013 年 5 月 9 日
Any warning or error message?
Walter Roberson
Walter Roberson 2013 年 5 月 9 日
Please display "a" inside the loop, so that we can see whether it thinks it is looping.
What is the one output file name?
lisa
lisa 2013 年 5 月 9 日
Here is the error message I get:
Index exceeds matrix dimensions.
Error in Regress_AODloop (line 16)
data1=data1(:,date1(a:a+11,:));
lisa
lisa 2013 年 5 月 9 日
'a' is in the loop, 2nd and 3rd lines:
data1=data1(:,date1(a:a+11,:));
data2=data2(:,date2(a:a+11,:));
Output file name (hopefully) = 'CF vs. AOD-%d.jpg',year
Thanks so much guys!!!
Jordan Monthei
Jordan Monthei 2013 年 5 月 9 日
are you sure that you are holding your plots each time they are outputting and its not just replacing the last plot with a different image every time it goes through the loop?

回答 (1 件)

Image Analyst
Image Analyst 2013 年 5 月 9 日

0 投票

2 件のコメント

lisa
lisa 2013 年 5 月 9 日
so basically I use dbstop if error and conditional breakpoint right? But I don't know why I get the error, not like his error which is pretty straightforward...Here is the error msg I get:
Index exceeds matrix dimensions.
Error in Regress_AODloop (line 16)
data1=data1(:,date1(a:a+11,:));
Image Analyst
Image Analyst 2013 年 5 月 9 日
It's difficult for us to debug without values for date1 and date2. However now that you know how to debug, you will quickly discover what a and a+11 are, and why one of them is not in the valid index range of date1.

この質問は閉じられています。

タグ

質問済み:

2013 年 5 月 9 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by