Clear Filters
Clear Filters

GUI to plot sine and cosine given amplitude and frequency

7 views (last 30 days)
My intention is to generate a GUI in Matlab in order to plot sine and cosine (chosen by a popup menu from user) while taking the values for amplitude and frequency from edittext inputs.
My GUI code shown below, can easily plot sine (or even cosine). However, it seems as if I have a problem making the popupmenu working correctly.
I realize this sounds very basic for actual GUI users, but it is essential for me to learn by making these simple cases work. any help is greatly appreciated.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Here is a link to my Matlab Script which plots but its popupmenu has problem:
https://www.dropbox.com/sh/gwjbllbzfdvyxe1/Th2Rn8V8fE

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 21 Aug 2012
you have just to program you puchbutton callback
function pushbutton1_Callback(hObject, eventdata, handles)
% when the button plot is pushed
f = str2num(get(handles.edit1,'String')); %geting f
A = str2num(get(handles.edit2,'String')); % geting A
t = 1:100
sine = A* sin(0.02*pi*f*t);
cosine = A * cos(0.02*pi*f*t);
val =double(get(handles.popupmenu1,'Value')); %geting popupmenu value(1 or 2)
if val==1
plot(sine);
else
plot(cosine)
end
  1 Comment
Amir
Amir on 22 Aug 2012
Edited: Amir on 22 Aug 2012
Thanks Azzi,
It worked!
One final question though:
I was wondering whether you have any suggestions as to how I could give the user an option of choosing a color for the plots by choosing from a Listbox? or perhaps even using the Slider for the color spectrum? I will try implementing my script draft and will update it here later on. But for now, can you think of a better way to do that?
Thanks, - Amir

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!