0

Matlab GUIDE を使用したプッシュボタンの次のコードがあります。シータ 1 とシータ 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

ただし、このコードで 2 つの問題に直面しています。

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 がこれらのコマンドを新しい Figure にプロットした理由を理解するのはまだ難しいですが。

于 2013-06-10T12:28:23.163 に答える