Graphics of sin,cos,tan,cot,sec,cosec
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
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
Geoff Hayes
on 3 Jan 2015
Egemen's answer moved here
It didnt worked :( i sent you a pm abaut that can you check it ?
Geoff Hayes
on 3 Jan 2015
Egemen - you need to provide some more details. When you say it didn't work, what do you mean? Was there any change at all or was an error generated or something else?
From your code (sent via pm) you have written
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
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);
state=get(handles.togglebutton2,'Value');
if state==1
plot(cosina);
else
plot(sina);
end
Try putting a breakpoint at the line where state is initialized, and then start playing with your GUI. When the debugger pauses at this line (because you have pressed the pushbutton1), what happens? What is state, and what curve is drawn on the axes?
I've attache a simplified version of your code that alternates between the sine and cosine curves given the state of the toggle button.
king
on 4 Jan 2015
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.
Categories
Find more on Graphics 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!