How do I plot single points only when using apps?

3 views (last 30 days)
I am learning apps via online videos (which is quite informative by the way). The problem I am having is how to best plot single points when creating code as opposed to an entire line of data. For example:
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
a = get(handles.slider1,'Value'); % Assigns instantanuous value of slider to a
x = 0:0.1:50; % Sets exact limits of x axis with step sizes of 0.1
y = sin(a*x); % Sets variable limits of y axis
plot(handles.axes1,x,y); % Plots values of x and y axis1 feature
This particular line of code adjusts data depending on a user's slider selection. I would like to know how to only show the instantaneous point of the slider within that axes1 display. What would I need to do? Additionally, if I were not to use a slider but an edit text box, how would that alter this line of code? If I can get some help with either in an example I believe I will be able to get back on track to creating my app. The end goal is to create a multi entry application that will show user entries (whether with a slider or edit text) in relation to one another in the same figure.
I appreciate all considerations ahead of time.
  2 Comments
Jan
Jan on 6 Oct 2021
What does this mean: "show the instantaneous point of the slider"?
Mario Richardson
Mario Richardson on 6 Oct 2021
I mean instead of showing the entire sine wave line, show just the point of where the slider (or the entry of an edit text box) is selecting. For example, the slider sets the x value. If the x value happens to be "0.5", show only the specific value of what "0.5" would be for both x and y positioning on the figure.

Sign in to comment.

Answers (1)

Cris LaPierre
Cris LaPierre on 6 Oct 2021
I would set up the slider to go from 1 to the number of points in the waveform, and then use the slider to select the index to plot.
a = get(handles.slider1,'Value'); % Assigns instantanuous value of slider to a
x = 0:0.1:50; % Sets exact limits of x axis with step sizes of 0.1
y = sin(x); % Sets variable limits of y axis
plot(handles.axes1,x(a),y(a),'o'); % Plots values of x and y axis1 feature
I would likely make x and y app properties so that they do not need to be recalculated everytime the slider changes value.

Categories

Find more on Develop uifigure-Based Apps in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!