0

我有以下代码用于使用 Matlab GUIDE 的按钮。它应该绘制一个旋转箭头,该箭头旋转到由 theta 1 和 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

但是,这段代码我面临两个问题:1)它只是绘制到一个新的matlab图形上,而不是在axes_turntable_xy上绘制它

2)它在执行到线轴(handles.axes_turntable_yz)后显示以下错误。错误如下:

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

有人能帮忙吗?

4

1 回答 1

0

好的,我调试了代码,这是上面代码中的问题行:

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

工作代码是:

 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);

这清除了我在 Matlab 中绘制的图形,而不是一些未指定的图形!尽管尽管将 axes.turntable_xy 设为当前轴,但仍然很难理解为什么 Matlab 将这些命令绘制在一个新图形中。

于 2013-06-10T12:28:23.163 回答