error = Index exceeds matrix dimension

조회 수: 1 (최근 30일)
fremond khoo
fremond khoo 2011년 3월 10일
good day to all matlab users and experts here,
i face some problems at work and hope to have some guidance from you all. i am working on my robotic arm project and i have develop a GUI programme to connect and run two stepper motor (motor 1 and motor 2)
i have succeeded in running motor 1 but motor 2 is not working. When i click the button CONNECT, this error came out:
??? Error using ==> serial.subsref at 137 Index exceeds matrix dimensions.
Error in ==> GUI_xyplotter>connect_m2_Callback at 129 obj2 = obj2(2)
Error in ==> gui_mainfcn at 96 feval(varargin{:});
Error in ==> GUI_xyplotter at 16 gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)GUI_xyplotter('connect_m2_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
can i know what is the problem and how to solve it?..thanks a lot in advance:)
  댓글 수: 2
Walter Roberson
Walter Roberson 2011년 3월 10일
We need the code for connect_m2_Callback
fremond khoo
fremond khoo 2011년 3월 10일
the code for connect_m2_Callback:
% --- Executes on button press in connect_m2.
function connect_m2_Callback(hObject, eventdata, handles)
obj2 = instrfind('Type','serial','Port','COM9','Tag','');
if isempty(obj2)
obj2 = serial('COM9');
else
fclose(obj2);
obj2 = obj2(2)
end
fopen(obj2);
(my COM port is COM9)

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2011년 3월 10일
instrfind used with a property-value pair returns an array of objects with the desired properties. As one of the properties is the port, in order for the array to have more than one element, there would have to be more than one serial object with that exact port. That seems an unlikely situation, so I do not see why your code assumes that there will be at least two objects returned when you go ahead and access obj2(2) ?
  댓글 수: 13
fremond khoo
fremond khoo 2011년 3월 15일
i had successfully run both of my motor^^..thanks a lot walter^^
fremond khoo
fremond khoo 2011년 3월 15일
good day walter,
can i ask now that i have successfully run both of my motor using MATLAB GUI, is it possible for me to program my two-link robotic arm to draw a straight line?..

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Objects에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by