How do I plot single points only when using apps?
3 次查看(过去 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!