How to plot multiple plots in one figure without overwriting

조회 수: 7 (최근 30일)
Joanne Hall
Joanne Hall 2023년 2월 5일
댓글: Joanne Hall 2023년 2월 5일
Dear Matlab,
I have attached sample data with 2 groups - their mean averaged power spectrum signal).
GOAL: to plot all data in one figure without overwriting the data each time, in a for loop. (with one group plotted in red lines, one average signal for each - and the other group plotted in black ones, one average signal for each participant).
The data are power spectrum outputs from matlab's pwelch() function, for 2 patient groups EEG data. In the below for loop, It plots each signal in the same prescribed figure, but the problem is that it overwrites the figure, so in the end, I only have one signal plotted (the last signal in the looping index).
%% plot all in one fig
for ic = 1: length(rowmeans2c)
figure(4),clf
hold on
plot(hz{ic},10*log10(rowmeans2c{ic}),"Color",'r')
end
for id = 1: length(rowmeans2d)
figure(4),clf
hold on
plot(hz{id},10*log10(rowmeans2c{id}),"Color",'k')
end
hold off
figure(4),
title('test')
Please help. Thank you so much in advance, as always!

채택된 답변

Image Analyst
Image Analyst 2023년 2월 5일
편집: Image Analyst 2023년 2월 5일
Get rid of the calls to figure() clf because it's clearing everything you've plotted prior to that.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by