Azzera filtri
Azzera filtri

GUI to plot sine and cosine given amplitude and frequency

5 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Azzi Abdelmalek
Azzi Abdelmalek il 21 Ago 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 Commento
Amir
Amir il 22 Ago 2012
Modificato: Amir il 22 Ago 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

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by