필터 지우기
필터 지우기

GUI to plot sine and cosine given amplitude and frequency

조회 수: 7 (최근 30일)
Amir
Amir 2012년 8월 21일
댓글: Bordin Vang 2020년 10월 27일
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
  댓글 수: 1
Bordin Vang
Bordin Vang 2020년 10월 27일
can you post your files again? the dropbox link isnt working anymore.

댓글을 달려면 로그인하십시오.

채택된 답변

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개)

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by