Plotting different figures by means of for loop

2 ビュー (過去 30 日間)
Riccardo Zabatta
Riccardo Zabatta 2021 年 8 月 3 日
コメント済み: the cyclist 2021 年 8 月 3 日
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 Center および File ExchangeGraphics Performance についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by