Filter löschen
Filter löschen

Problem in executing multiple for loops together for subplotting

2 Ansichten (letzte 30 Tage)
Md. Moklesur Rahman
Md. Moklesur Rahman am 3 Sep. 2012
Hello everybody,
I am trying to make 365 plots from one file (daily plot for yearly data). I am using the following code to make three subplots which is producing three subplots but only the third plot in the third subplot. Seems like the first two for loops are not reading the data and thus, the plots are missing. The problem is only inside the loop. Does anybody have any idea why the first two for loops are not working? Thank you very much in advance for helping me to get rid of this situation.
close all; clc; fid = fopen('TGM_2009_m.dat','r'); data_f1 = textscan(fid,'%s%s%f', 'delimiter', ' ', 'MultipleDelimsAsOne', true, 'collectoutput', true,'headerlines',1); fclose(fid) data1 = data_f1{1,1}; data2 = data_f1{1,2}(:,1); A = data1(:,1); B = data1(:,2); Q = strcat(A, {' '} , B); timevec = datevec(Q); firstidx = datenum(timevec(1,:)) - datenum(timevec(1,1), timevec(1,2), timevec(1,3), 0, 0, 0)+1; newdata = NaN(7248,1); R = cumsum([firstidx; round(diff(datenum(timevec)*24*1))]); newdata(R,:) = data2; a = NaN(1512,1); newdata = vertcat(a,newdata);
fid = fopen('ksjoz_2009_m.dat','r'); data_f1 = textscan(fid,'%s%s%f%f%f%f', 'delimiter', ' ', 'MultipleDelimsAsOne', true, 'collectoutput', true,'headerlines',1); fclose(fid) data11 = data_f1{1,1}; data22 = data_f1{1,2}(:,1); A1 = data11(:,1); B1 = data11(:,2); Q1 = strcat(A1, {' '} , B1); timevec1 = datevec(Q1); firstidx1 = datenum(timevec1(1,:)) - datenum(timevec1(1,1), timevec1(1,2), timevec1(1,3), 0, 0, 0)+1; newdata1 = NaN(440640,1); R1 = cumsum([firstidx1; round(diff(datenum(timevec1)*24*60))]); newdata1(R1,:) = data22; b = NaN(84960,1); newdata1 = vertcat(b,newdata1);
fid = fopen('ksj_co2_2009_m.dat','r'); data_f2 = textscan(fid,'%s%s%f', 'delimiter', ' ', 'MultipleDelimsAsOne', true, 'collectoutput', true, 'headerlines',1); fclose(fid) data1111 = data_f2{1,1}; data2222 = data_f2{1,2}; A3 = data1111(:,1); B3 = data1111(:,2); Q3 = strcat(A3, {' '} , B3); timevec3 = datevec(Q3); firstidx3 = datenum(timevec3(1,:)) - datenum(timevec3(1,1), timevec3(1,2), timevec3(1,3), 16, 29, 0)+1; newdata3 = NaN(415232,1); R3 = cumsum([firstidx3; round(diff(datenum(timevec3)*24*60))]); newdata3(R3,:) = data2222; d = NaN(110368,1); newdata3 = vertcat(d,newdata3);
for i = 1:24:size(newdata,1) start = i; finish = start + 23; dailydata = newdata(start:finish,:);
for j =1:1440:size(newdata1,1)
start1 = j;
finish1 = start1 + 1439;
dailydata1 = newdata1(start1:finish1,:);
for k = 1:1440:size(newdata3,1)
start2 = k;
finish2 = start2 + 1439;
dailydata2 = newdata3(start2:finish2,:);
figure;
x1 = linspace(0,24,length(dailydata));
x2 = linspace(0,24,length(dailydata1));
x3 = linspace(0,24,length(dailydata2));
subplot(3,1,1)
plot(x1,dailydata(:,1),'ro-','MarkerSize',2)
set(gca,'xlim',[0 24],'xtick',[],...
'xticklabel',[])
ylabel('TGM (ng/m^3)','FontSize',10);
title(datestr(timestampvec_WD(k,:), 'yyyy-mm-dd'));
subplot(3,1,2);
plot(x2,dailydata1(:,1),'ro-','MarkerSize',2)
set(gca,'xlim',[0 24],'xtick',[],...
'xticklabel',[])
ylabel('O_3 (ppb)','FontSize',10);
subplot(3,1,3);
xxx = plot(x3,dailydata2(:,1),'ro-','MarkerSize',2)
set(gca,'xlim',[0 24],'xtick',[0:2:24],...
'xticklabel',[0:2:24])
ylabel('CO_2 (ppb)','FontSize',10);
xlabel('Time (hour)');
saveas(xxx, strcat('G:\KSS data\O3 final data\Final files_O3_CO_WD\daily_plots_2009\',datestr(timestampvec_WD(k,:), 'yyyy-mm-dd')),'pdf');
end
end
end

Antworten (1)

Jan
Jan am 3 Sep. 2012
This seems to be a problem for the debugger. Set a break point in the first line of your code and step through the program line by line. Inspecting the values of the variables will help you to find out, what's going on.

Community Treasure Hunt

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

Start Hunting!

Translated by