How to plot multiple figures using for loop
Mostrar comentarios más antiguos
Hi.
I have 40 variable data that I want to plot on 3D.
Let's say the data: Data_1, Data_2, Data_3, ...... Data_40.
Each has 43x6.
I first loaded the data from the directory:
LIST=dir('*.mat');
N = length(LIST);
for ii = 1:N
load(['Column_' num2str(ii) '.mat'])
LIST(ii).name(1:end-4);
end
It works when I individually plot the figure:
figure
mapshow((Data_1(:,1:2)),(Data_1(:,3:4)),(Data_1(:,5:6)),'DisplayType','surface');
demcmap((Data_1(:,5:6)));
view(3);
xlabel('x (meter)', 'fontsize',13);
ylabel('y (meter)', 'fontsize',13);
zlabel('z (meter)', 'fontsize',13);
title('Column 1', 'FontSize', 15);
axis normal
The reason why I created mapshow((S(:,1:2)),(S(:,3:4)),(S(:,5:6)),'DisplayType','surface') is because the column 1 and 2 arrays the X-axis, 3 and 4 Y-axis, and 5 and 6 Z-axis.
However, it seems I work a lot with this. So, I want to plot each of Data_1, Data_2,....Data_40 separately using for loop.
So, I write:
for i=1:numel(LIST)
S=(LIST(i).name(1:end-4));
figure(i)
mapshow((S(:,1:2)),(S(:,3:4)),(S(:,5:6)),'DisplayType','surface');
demcmap((S(:,5:6)));
view(3);
end
I don't know how to array the mapshow using for loop.
I am sorry that I am still new using MATLAB.
Appreciate your reply.
Thank you.
10 comentarios
AMIT POTE
el 28 de Jun. de 2022
Could you be more specific? Do you want to plot all of them in the same axes?
DV
el 28 de Jun. de 2022
What is the purpose of this part of the code:
load(['Column_' num2str(ii) '.mat'])
LIST(ii).name(1:end-4);
The 2nd line does nothing. Maybe you mean (sprintf looks simpler):
LIST(ii).name = load(sprintf('Column_%d.mat', ii));
What is the contents of the field "name"? What is stored in the MAT files?
DV
el 28 de Jun. de 2022
Jan
el 28 de Jun. de 2022
Just a note: "Data_1" is a bad choice. Prefer to use arrays instead of hiding indices in the names of variables.
Jan
el 30 de Jun. de 2022
What does a:(a+1) mean, if a is the vector 1:41 ?
DV
el 30 de Jun. de 2022
@DV: This does not work in Matlab. Try it:
a = 1:3
a:(a+1)
The colon operator uses the 1st element only, if an array is provided as input, so a:(a+1) is the same as: a(1):a(1)+1 . Therefore "the plot should be" from you comment above does not clarify, what you want, because it does not work.
I still do not understand, what you want to achieve.
DV
el 30 de Jun. de 2022
Respuestas (1)
Devang Tavkari
el 6 de Jul. de 2022
1 voto
You need to store the (data1 - data 40) in a cell and then plot the data from the cell using a for loop. so when you load the data from your directrory save it in a cell, later make a for loop of the lengh of that cell and plot the data from every cell. you can later also use saveas command to save your plots.
Categorías
Más información sobre Annotations 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!