How to run this code in a for loop?
Mostrar comentarios más antiguos
Hi all!
I have a code that requires to go to the folder, calls mat files and then plot images. I want to run everything in a for loop. Could you please tell me how can I do this? The individual code is like this -
%% Day 01
cd(strcat('/Users/aahmed78/PhD/Data/Day26/Two Particle'));
load('Day01_Path.mat');
Leng = numel(t);
plot(p0_x,p0_y);
for i = 1:Leng
figure(1); hold on;
title('26-April-2015 to 02-May-2015','fontsize',20);
plot(px(i,:),py(i,:),'o','MarkerSize',2,'color',[0 1 0]);
end
hold on;
%% Day 02
cd(strcat('/Users/aahmed78/PhD/Data/SWOT/Day27/Two Particle'));
load('Day02_Path.mat');
Leng = numel(t);
plot(p0_x,p0_y);
for i = 1:Leng
figure(1); hold on;
title('26-April-2015 to 02-May-2015','fontsize',20);
plot(px(i,:),py(i,:),'o','MarkerSize',2,'color',[0 1 0]);
end
hold on;
%% Day 03
cd(strcat('/Users/aahmed78/PhD/Data/SWOT/Day28/Two Particle'));
load('Day03_Path.mat');
Leng = numel(t);
plot(p0_x,p0_y);
for i = 1:Leng
figure(1); hold on;
title('26-April-2015 to 02-May-2015','fontsize',20);
plot(px(i,:),py(i,:),'o','MarkerSize',2,'color',[0 1 0]);
end
hold on;
an so on for the 7 days. Please note that the folders name are Day26, Day27, Day28, ..., Day32. But the .mat file that I call is Day01, Day02, ... ,Day07. Rest of the codes are the same. I wrote down this code to solve -
for k = 1:7
cd(strcat('/Users/aahmed78/PhD/Data/Day',num2str(day(k+26)),'/Two Particle'));
load('Day0',num2str(day),'_Path.mat');
Leng = numel(t);
plot(p0_x,p0_y); hold on;
for i = 1:Leng
figure(1); hold on;
title('26-April-2015 to 02-May-2015','fontsize',25);
plot(px(i,:),py(i,:),'o','MarkerSize',2);
hold on;
end
hold on;
end
But it is showing me
Index exceeds the number of array elements (1).
Any feedback from you guys will be much appreciated!
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Data Type Identification en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!