error = Index exceeds matrix dimension

1 次查看(过去 30 天)
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