Graphics of sin,cos,ta​n,cot,sec,​cosec

9 ビュー (過去 30 日間)
king
king 2015 年 1 月 3 日
コメント済み: Image Analyst 2015 年 1 月 7 日
Hi everybody, i am trying to design a gui that shows these function graphics.I am using only axes1. And i am using 3 push button
-sin(cos)
-tan(cotan)
-sec(cosec)
and i have 1 toggle button
-Shift
The problem is if you push button 1 (sin(cos)) it shows sin fucntion correctly but i want to use my toggle button too. Example if i press toggle button,i want to change the axes sin to cos.I am new at this and i couldnt to that can you help me ? I used this code on pushbutton1
f=str2num(get(handles.edit7,'String'));
A=str2num(get(handles.edit6,'String'));
F=str2num(get(handles.edit5,'String'));
faz=str2num(get(handles.edit8,'String'));
t=1:100
sina=F+A*sin(2*pi*f*t+faz);
cosina=F+A*cos(2*pi*f*t+faz);
val=double(get(handles.pushbutton1,'Value'));
if val==1
plot(sina);
else
plot(cosina)
end

回答 (1 件)

Geoff Hayes
Geoff Hayes 2015 年 1 月 3 日
Egeman - I think that you should be using your toggle button (presumably named togglebutton1) rather than the pushbutton1 in order to decide which curve to plot. Your code is
val=double(get(handles.pushbutton1,'Value'));
if val==1
plot(sina);
else
plot(cosina)
end
Whereas it should be something like
state=get(handles.togglebutton1,'Value');
if state==1
plot(cosina);
else
plot(sina);
end
In the above, the value returned from get(handles.togglebutton1,'Value') is already of data type double so we don't need to convert or cast it to the double data type. We call this value the state of the toggle button. If the toggle button is pressed, then the state is 1 and so would correspond to the plotting of the cosine curve. If the toggle button is not pressed, then the state is 0 and so would correspond to the plotting of the sine curve.
Try making the above change and see what happens!
  4 件のコメント
king
king 2015 年 1 月 4 日
Done ! Thanks !
Image Analyst
Image Analyst 2015 年 1 月 7 日
You can further thank him by voting for his answer and officially Accepting it to give him reputation points.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by