How do I plot single points only when using apps?

조회 수: 2 (최근 30일)
Mario Richardson
Mario Richardson 2021년 10월 6일
답변: Cris LaPierre 2021년 10월 6일
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
Jan
Jan 2021년 10월 6일
What does this mean: "show the instantaneous point of the slider"?
Mario Richardson
Mario Richardson 2021년 10월 6일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Cris LaPierre
Cris LaPierre 2021년 10월 6일
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.

카테고리

Help CenterFile Exchange에서 Develop uifigure-Based Apps에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by