Plotting different figures by means of for loop

조회 수: 1 (최근 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 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