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

조회 수: 5 (최근 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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by