0

I have the following code for a pushbutton using Matlab GUIDE.It is supposed to plot a rotating arrow which rotates to the angles specified by theta 1 and theta 2.

function start_pushbutton_callback_Callback(hObject, eventdata, handles)
% hObject    handle to start_pushbutton_callback (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles = guidata(hObject);
theta1 = handles.xy_angle; 
theta2 = handles.yz_angle; 
delay = handles.speed;
axes(handles.axes_turntable_xy); 
R= 1; %Radius of the turntable
E=[0;0;0];
C=[-2;0;0];% points on the X axis
D=[2;0;0]; % points on the X axis
G=[0;2;0]; % points on the Y axis
H=[0;-2;0];% points on the Y axis

for th =1:1:theta1
clf;
Radius =1;
[x,y,z] = cylinder(Radius,200);
plot(x(1,:),y(1,:))
axis equal
L1= [R*cosd(th);R*sind(th);0];
drawvector(E,L1); % call the drawvector function, as previously
line([C(1),D(1)],[C(2),D(2)]);
line([G(1),H(1)],[G(2),H(2)]);
axis([-2 2 -2 2]);
grid on;
pause(delay);
end;

axes(handles.axes_turntable_yz) ;
R= 1; %Radius of the turntable
E=[0;0;0];
C=[-2;0;0];% points on the X axis
D=[2;0;0]; % points on the X axis
G=[0;2;0]; % points on the Y axis
H=[0;-2;0];% points on the Y axis

for th =1:1:theta2;
clf;
Radius = 1;
[x,y,z] = cylinder(Radius,200);
plot(x(1,:),y(1,:))
axis equal
L1= [R*cosd(th);R*sind(th);0];
drawvector(E,L1); % call the drawvector function
line([C(1),D(1)],[C(2),D(2)]);
line([G(1),H(1)],[G(2),H(2)]);
axis([-2 2 -2 2]);
grid on;
pause(delay);
end

However, I am facing two problems with this code: 1) It simply plots onto a new matlab figure instead of plotting it on axes_turntable_xy-

2) It displays the following error afer executing till the line axes(handles.axes_turntable_yz). The error is as follows:

Error using axes
Invalid object handle

Error in turntable_interface_model>start_pushbutton_callback_Callback (line 235)
axes(handles.axes_turntable_yz) ;

Error in gui_mainfcn (line 96)
        feval(varargin{:});

Error in turntable_interface_model (line 42)
    gui_mainfcn(gui_State, varargin{:});

Error in
@(hObject,eventdata)turntable_interface_model('start_pushbutton_callback_Callback',hObject,eventdata,guidata(hObject))


Error while evaluating uicontrol Callback

Can anyone help with this?

Ananth Saran
  • 207
  • 2
  • 17
  • Can you post the code that sets handles.axes_turntable_xy? Presumably you do this in another function in the gui. – grantnz Jun 10 '13 at 10:42
  • @grantnz:I'm using GUIDE, so i didn't have to create any code that sets handles.axes_turntable_xy. While creating the GUI, i set the handle visibility to 'on' and the tag to 'axes_turntable_xy' using the property inspector. – Ananth Saran Jun 10 '13 at 11:07
  • As a first step in debugging, either (1) set a breakpoint in this function and check the fields and values of your `handles` arg, or (2) use `disp(fieldnames(handles))` to print the valid fields to the command window. – tmpearce Jun 10 '13 at 12:06
  • Also: why the line `handles = guidata(hObject);`? You're overwriting the `handles` argument that is passed in. – tmpearce Jun 10 '13 at 12:08
  • @tmpearce: I got an answer! It's been posted below. And i have removed the line. Thanks for that! – Ananth Saran Jun 10 '13 at 12:29

1 Answers1

0

Okay, I debugged the code and this was the problematic line in the above code:

for th =1:1:theta1
clf;
Radius =1;
[x,y,z] = cylinder(Radius,200);

The working code is:

 for th1 =1:1:theta1
 cla(handles.axes_turntable_xy); %clears the figure handles.axes_turntable_xy
 Radius =1;
 [x,y,z] = cylinder(Radius,200);

This clears the figure I am plotting in in Matlab, not some unspecified figure! Although it's still hard to understand why Matlab was plotting these commands in a new figure inspite of making axes.turntable_xy the current axes.

Ananth Saran
  • 207
  • 2
  • 17