How do I plot single points only when using apps?
조회 수: 2 (최근 30일)
이전 댓글 표시
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
답변 (1개)
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Develop uifigure-Based Apps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!