Plotting multiple plots in for loop

10 ビュー (過去 30 日間)
Joel Schelander
Joel Schelander 2021 年 4 月 23 日
編集済み: Abdolkarim Mohammadi 2021 年 4 月 23 日
I have two sets of cells in the cell array AAG
cell 1 has 36x1 cells, everyone of these is a 1000x1 double
cell2 has 486x1 cells, everyone of these is a 1000x1 double
On the x axis I want 1 and 2
On the y axis I want all the values in cell1 on x=1 and all the values in cell2 on x=2
My approach so far is this:
This does however result in two plots, I want the graphs in one plot. How can I achieve this?
for y=1:2
xx=cell(length(AAG{y}),1);
for o=1:length(AAG{y})
xx{o} =AAG{y}{o};
end
figure
for k1 = 1:length(AAG{y})
plot(ones(1,numel(xx{k1}))*y, xx{k1})
end
hold on
end

採用された回答

Abdolkarim Mohammadi
Abdolkarim Mohammadi 2021 年 4 月 23 日
編集済み: Abdolkarim Mohammadi 2021 年 4 月 23 日
You should not use the figure command inside a loop. Each call to command creates a new figure window. When you call the plot function, it automatically creates a figure window. Your code should look like the following. Please note the the hold on command creates a figure window.
hold on
for i = 1:2
for j = 1:2
plot (x);
end
end
hold off

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by