Using a slider to control a plot.

114 views (last 30 days)
brett cursey
brett cursey on 15 Apr 2016
Edited: brett cursey on 15 Apr 2016
I have a project that we have to plot Sinusoids. I already figured out how to add the Amp and Freq from user input in GUI, but I'm suppose to use a slider to move the sin, acting as a phase shift between -2pi to 2pi. I am completing stomped. Thank you for any help you could give.
function Amp1_Callback(hObject, eventdata, handles) % hObject handle to Amp1 (see GCBO) % eventdata reserved - to be defined in Amp1 future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Amp1 as text % str2double(get(hObject,'String')) returns contents of Amp1 as Amp1 double Amp1 = str2double(get(hObject,'String')); setappdata(handles.Amp1,'Amp1',Amp1);
% --- Executes during object creation, after setting all properties. function Amp1_CreateFcn(hObject, eventdata, handles) % hObject handle to Amp1 (see GCBO) % eventdata reserved - to be defined in Amp1 future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have Amp1 white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end
function Freq1_Callback(hObject, eventdata, handles) % hObject handle to Freq1 (see GCBO) % eventdata reserved - to be defined in Amp1 future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Freq1 as text % str2double(get(hObject,'String')) returns contents of Freq1 as Amp1 double Freq1 = str2double(get(hObject,'String')); setappdata(handles.Freq1,'Freq1',Freq1);
% --- Executes during object creation, after setting all properties. function Freq1_CreateFcn(hObject, eventdata, handles) % hObject handle to Freq1 (see GCBO) % eventdata reserved - to be defined in Amp1 future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have Amp1 white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end
% --- Executes on slider movement. function P1_Callback(hObject, eventdata, handles) % hObject handle to P1 (see GCBO) % eventdata reserved - to be defined in Amp1 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
% --- Executes during object creation, after setting all properties. function P1_CreateFcn(hObject, eventdata, handles) % hObject handle to P1 (see GCBO) % eventdata reserved - to be defined in Amp1 future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have Amp1 light gray background. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]); end
% --- Executes on button press in Btn1. function Btn1_Callback(hObject, eventdata, handles) % hObject handle to Btn1 (see GCBO) % eventdata reserved - to be defined in Amp1 future version of MATLAB % handles structure with handles and user data (see GUIDATA)
%For Sine input 1 Amp1 = getappdata(handles.Amp1,'Amp1'); Freq1 = getappdata(handles.Freq1,'Freq1'); t = 0:.01:1; y = Amp1*sin(Freq1*t); axes(handles.Plot1); plot(t,y); xlabel('gayness'); ylabel('Super');

Answers (1)

Stephen23
Stephen23 on 15 Apr 2016

Community Treasure Hunt

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

Start Hunting!