Plotting different figures by means of for loop
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Riccardo Zabatta
am 3 Aug. 2021
Kommentiert: the cyclist
am 3 Aug. 2021
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.
0 Kommentare
Akzeptierte Antwort
the cyclist
am 3 Aug. 2021
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 Kommentar
the cyclist
am 3 Aug. 2021
Also, it is strongly recommended to not use cell as a variable name, because it is a MATLAB function.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!