Cannot overlay new plot on an existing subplot

17 Ansichten (letzte 30 Tage)
Branko Celler
Branko Celler am 23 Okt. 2024
Kommentiert: Branko Celler am 23 Okt. 2024 um 22:29
I cannot believe that I have been forced to ask this question, but your help would be greatly appreciated!
I generate a plot (figure(10) of three subplots, all are hold on
I use ginput(2) to fidentify portion of good data in subplot(3,1,1) from which I need to detect peak points using a custom function that uses the built in function findpeaks
I want to mark over the original data in figure(10), subplot(3,1,1) the detected peak points
When I run the program, the overwrite either goes to a new figure or if figure(10) is selected it kills the previous figure(10) and plots a new figure(10) showing only the detected points
input data arrays are IABP, PPG and ECG (They are too long to provide here, approximately 40,000 points each)
The simplified code snippet is below;
% Select good data for determination of BP parameters
figure(10)
orient Landscape;
set(gcf,'units', 'normalized', 'outerposition', [0 0 1 1]);
%==========================================================================
ax(1)=subplot(3,1,1);
plot(IABP,'b'), hold on
v1=axis;
ylabel('IABP'), hold on
%--------------------------------------------------------------------------
ax(2)=subplot(3,1,2);
plot(ECG, 'k'), hold on
v2=axis;
ylabel('ECG'), hold on
%--------------------------------------------------------------------------
ax(3)=subplot(3,1,3);
plot(PPG,'k'), hold on
v3=axis;
ylabel('PPG'), hold on
%--------------------------------------------------------------------------
[x,y]=ginput(2); % Select good area of data
x=round(x);
% Create BP data from IABP segment
BP=IABP(x(1):x(2));
%==========================================================================
% Calculate SBP, DBP and MP
[DBP_LOCS,DBP,SBP_LOCS, SBP,HR] = IABP_PulseDetect(Fs,1,BP,LookbackBP); % Calculates SBP and DBP peaks, uses findpeaks
figure(10) % Want to locate detected SBP points and DBP points on figure(10) subplot(3,1,1)
subplot(3,1,1)
scatter(SBP_LOCS, SBP,'ro'), hold on
scatter(DBP_LOCS,DBP,'go'), hold on
axis([v1(1) v1(2) v1(3) v1(4)])
%linkaxes(ax,'x')
hold on
pause
%--------------------------------------------------------------------------
Can provide code for function, IABP_PulseDetect, but any figures opened in that subroutine are closed before exiting function.
I find MATLAB incredibly useful and love using it, but sometimes why something does not work can consume an extraordinary amount of time.
I thank you for your assistance!

Akzeptierte Antwort

dpb
dpb am 23 Okt. 2024 um 5:02
% Select good data for determination of BP parameters
figure(10)
orient Landscape;
set(gcf,'units', 'normalized', 'outerposition', [0 0 1 1]);
%==========================================================================
ax(1)=subplot(3,1,1);
plot(IABP,'b'), hold on
v1=axis;
ylabel('IABP'), hold on
%--------------------------------------------------------------------------
ax(2)=subplot(3,1,2);
plot(ECG, 'k'), hold on
v2=axis;
ylabel('ECG'), hold on
%--------------------------------------------------------------------------
ax(3)=subplot(3,1,3);
plot(PPG,'k'), hold on
v3=axis;
ylabel('PPG'), hold on
%--------------------------------------------------------------------------
[x,y]=ginput(2); % Select good area of data
x=round(x);
% Create BP data from IABP segment
BP=IABP(x(1):x(2));
%==========================================================================
% Calculate SBP, DBP and MP
[DBP_LOCS,DBP,SBP_LOCS, SBP,HR] = IABP_PulseDetect(Fs,1,BP,LookbackBP); % Calculates SBP and DBP peaks, uses findpeaks
%figure(10) % Want to locate detected SBP points and DBP points on figure(10) subplot(3,1,1)
%subplot(3,1,1)
scatter(ax(1),SBP_LOCS, SBP,'ro')
scatter(ax(1),DBP_LOCS,DBP,'go')
axis([v1(1) v1(2) v1(3) v1(4)])
%linkaxes(ax,'x')
hold on
pause
You saved the handle to the subplot axis when you created it; use it when you need to address that subplot again...
  3 Kommentare
dpb
dpb am 23 Okt. 2024 um 17:35
"Close all seems a very dangeroud command,..."
Well, with 'all' it certainly will do what it says it will; as with clear or delete, one needs to be sure one is only operating on what one wishes to operate on.
The penchant of instructors to require/promote putting those at the beginning of scripts is teaching a very bad habit for their convenience; it does require that the student have everything required for the homework assignment defined in the submitted solution, but it teaches a very bad practice in the real world; rarely are either needed and encapsulation in functions is a much better solution than using scripts, anyways.
Branko Celler
Branko Celler am 23 Okt. 2024 um 22:29
The presumption is that a command within a function operates only in that function! That is the misconception! Close all operates across the whole work space!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by