How to plot multiple figures using for loop
6 views (last 30 days)
Show older comments
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 Comments
Jan
on 30 Jun 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.
Answers (1)
Devang Tavkari
on 6 Jul 2022
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.
0 Comments
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!