When creating an app, how do you plot points on top of a line on a UI axis?

3 views (last 30 days)
% We will write the following code in the button push function,
% since we want the push of this button to 1.)
main_axes = app.UIAxes;
weekval = app.WeekDropDown.Value;
drugval = app.DrugDropDown.Value;
temp_time = app.ecg_data.DATA.(weekval).(drugval).Time;
temp_ecg = app.ecg_data.DATA.(weekval).(drugval).ECG;
[peaksx, peaksy] = findpeaks(temp_ecg);
hold(main_axes, 'on' )
%This plots the line
plot(main_axes,temp_time,temp_ecg)
hold(main_axes, 'off' )
hold(main_axes, 'on' )
%This plots the points
plot(main_axes, peaksy,peaksx, '.');
hold(main_axes, 'off' )

Answers (2)

dpb
dpb on 2 May 2023
% We will write the following code in the button push function,
% since we want the push of this button to 1.)
main_axes = app.UIAxes;
weekval = app.WeekDropDown.Value;
drugval = app.DrugDropDown.Value;
temp_time = app.ecg_data.DATA.(weekval).(drugval).Time;
temp_ecg = app.ecg_data.DATA.(weekval).(drugval).ECG;
[peaksx, peaksy] = findpeaks(temp_ecg);
%This plots the line
plot(main_axes,temp_time,temp_ecg)
hold(main_axes, 'on' )
%This plots the points
plot(main_axes, peaksy,peaksx, '*');
Don't reset hold until ready to draw a new figure/axes/plot...do that only at a beginning or if give user the option to clear the axes.
The above should have worked, likely just couldn't see the marker using just a '.' with no larger marker size than default.
The '*' should show up; salt to suit with color/size/marker/etc.,...

Image Analyst
Image Analyst on 2 May 2023
Try xline or yline
% Get limits of axes
xl = xlim
yl = ylim
xine(xl(1), 'Color', 'r', 'LineWidth', 5) % Draw line along left edge of axes box.
xine(xl(2), 'Color', 'r', 'LineWidth', 5) % Draw line along right edge of axes box.
yine(yl(1), 'Color', 'r', 'LineWidth', 5) % Draw line along bottom edge of axes box.
yine(yl(2), 'Color', 'r', 'LineWidth', 5) % Draw line along top edge of axes box.

Categories

Find more on Graphics Object Properties in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!