[英]Plotting onto specified axes in Matlab GUIDE
我有以下使用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
有人能幫忙嗎?
好的,我調試了代碼,這是上面代碼中的問題行:
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中繪制的圖形,而不是一些未指定的圖形! 盡管仍然很難理解為什么Matlab會在新圖中繪制這些命令,盡管將axis.turntable_xy設置為當前軸。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.