Why my GUI keeps producing error when I run it?
Show older comments
When I run the code, it gives me these errors. Can anyone help me solve this problem? I am using the 2019 b version.
Index at position 2 exceeds array boundary (cannot exceed 1)
Error Sample_2>btn_Forward_Callback (line 168)
handles.Pos_X.String=num2str(floor(T(1,4)));
Error gui_mainfcn (line 95)
feval(varargin{:});
Error Sample_2 (line 42)
gui_mainfcn(gui_State, varargin{:});
This is my code. Edit Rik: removed empty functions and default GUIDE code at the function start. The full original code is attached as m-file.
function varargout = Sample_2(varargin)
%standard GUIDE header, OpeningFcn and OutputFcn
% --- Executes on button press in btn_Forward.
function btn_Forward_Callback(hObject, eventdata, handles)
% hObject handle to btn_Forward (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Th_1=str2double(handles.Theta_1.String)*pi/180;
Th_2=str2double(handles.Theta_2.String)*pi/180;
Th_3=str2double(handles.Theta_3.String)*pi/180;
L_1=20;
L_2=50;
L_3=40;
L(1)=Link([0 L_1 0 pi/2]);
L(2)=Link([0 0 L_2 0]);
L(3)=Link([0 0 L_3 0 ]);
Robot=SerialLink(L);
Robot.name='Sample_2';
Robot.plot([Th_1 Th_2 Th_3]);
T = Robot.fkine([Th_1 Th_2 Th_3]);
handles.Pos_X.String=num2str(floor(T(1,4)));
handles.Pos_Y.String=num2str(floor(T(2,4)));
handles.Pos_Z.String=num2str(floor(T(3,4)));
% --- Executes on button press in btn_Inverse.
function btn_Inverse_Callback(hObject, eventdata, handles)
% hObject handle to btn_Inverse (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
PX=str2double(handles.Pos_X.String);
PY=str2double(handles.Pos_Y.String);
PZ=str2double(handles.Pos_Z.String);
L_1=20;
L_2=50;
L_3=40;
L(1)=Link([0 L_1 0 pi/2]);
L(2)=Link([0 0 L_2 0]);
L(3)=Link([0 0 L_3 0 ]);
Robot=SerialLink(L);
Robot.name='Sample';
T=[1 0 0 PX;
0 1 0 PY;
0 0 1 PZ;
0 0 0 1;]
J=Robot.ikine(T,[0 0 0],[1 1 1 0 0 0])*180/pi;
handles.Theta_1.String=num2str(floor(J(1)));
handles.Theta_2.String=num2str(floor(J(2)));
handles.Theta_3.String=num2str(floor(J(3)));
Robot.plot(J*pi/180);
2 Comments
Mohammad Sami
on 26 Mar 2020
Look at your variable "T". does it have 4 columns. from the error it appears that this variable only has 1 column.
Accepted Answer
More Answers (0)
Categories
Find more on Matrices and Arrays 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!