GUI to plot sine and cosine given amplitude and frequency

8 次查看(过去 30 天)
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

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2012-8-21
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 个评论
Amir
Amir 2012-8-22
编辑:Amir 2012-8-22
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

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by