Plotting different figures by means of for loop

1 次查看(过去 30 天)
Hi!
I have a problem with plotting by means of a for loop.
I'll try to explain my case.
I have a 3x4 cell containing mx2 arrays (the two columns represent displacement and load of FE analyses I am performing).
I want to plot load-displacement curves; I want 1 graph per cell row, on each graph 4 curves will be displayed (1 per cell column).
I'll show you how I have tried so far:
for i = 1:cellrows
figure(i);
if j < cellcolumns+1
plot(cell{i,j}(:,1),cell{i,j}(:,2))
hold on
else
hold off
j = 1;
end
end
This is producing the 3 graphs I want, but only 1 curve per graph is displayed (I guess the fourth one, haven't checked exactly). What am I missing?
Hope it's clear, thanks for anyone who's answering.

采纳的回答

the cyclist
the cyclist 2021-8-3
I believe this does what you are trying to do:
% Create some fake data [Use your real data instead]
m = 5;
C = cell(3,4);
C = cellfun(@(x)[(1:m)' rand(1)*(1:m)'],C,'UniformOutput',false);
% Get the size of the cell array
[cellrows,cellcolumns] = size(C);
for i = 1:cellrows % Loop over the rows
figure(i); % New figure for each row
hold on % Make sure each plot does not overwrite the others in this row
for j = 1:cellcolumns
plot(C{i,j}(:,1),C{i,j}(:,2))
end
end
  1 个评论
the cyclist
the cyclist 2021-8-3
Also, it is strongly recommended to not use cell as a variable name, because it is a MATLAB function.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by