error = Index exceeds matrix dimension

1 visualizzazione (ultimi 30 giorni)
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 Commenti
Walter Roberson
Walter Roberson il 10 Mar 2011
We need the code for connect_m2_Callback
fremond khoo
fremond khoo il 10 Mar 2011
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)

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 10 Mar 2011
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 Commenti
fremond khoo
fremond khoo il 15 Mar 2011
i had successfully run both of my motor^^..thanks a lot walter^^
fremond khoo
fremond khoo il 15 Mar 2011
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?..

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Graphics Objects in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by