Graphics of sin,cos,tan,cot,sec,cosec
9 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Geoff Hayes
on 3 Jan 2015
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 Comments
Image Analyst
on 7 Jan 2015
You can further thank him by voting for his answer and officially Accepting it to give him reputation points.
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!