Create multiple subplot from one loop

3 次查看(过去 30 天)
Hi all,
I have 359 data set which can be used to create individual graphs, but that's too much. So i want to create 18 subplots where each have 20 graphs. The code i have, creates a subplot with the 1st 20 graphs and stops. I need it to carry on creating more subplots every 20 graphs until theres no more.
for j=2:length(xt); % xt 359x1 double
subplot(5,4,j-1)
plot(xs,yinternew(:,j)) % xs 17x1 double yinternew 17x359 double
xlabel('Strain, %')
ylabel('H3H0 Torque')
end
Do you guys know how to do this?
Thank you for your help.

采纳的回答

Voss
Voss 2023-6-16
% some made-up data, for demonstration:
xs = 1:17;
yinternew = reshape(1:17*359,17,[]);
n_lines = 20; % 20 lines per subplot
n_total = size(yinternew,2); % n_total lines total
for j = 1:ceil(n_total/n_lines)
subplot(5,4,j)
idx = (j-1)*n_lines+2:j*n_lines+1;
idx(idx > n_total) = [];
plot(xs,yinternew(:,idx)) % xs 17x1 double yinternew 17x359 double
xlabel('Strain, %')
ylabel('H3H0 Torque')
end
  6 个评论
S C
S C 2023-6-25
Hi, thank you. I used all 3 of your suggestions and modified slighlty to make it work.
Dyuman Joshi
Dyuman Joshi 2023-6-26
Hello @S C, if this answer solved your problem, please consider accepting it.
Accepting an answer helps the author to gain reputation points and it also helps others that might face a similar problem in the future.
If there are more than 1 answers, you can also vote for the answers that helped you.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by