Array indices must be positive integers or logical values.

1 visualizzazione (ultimi 30 giorni)
I am trying to do app design for forward kinematics of 6 dof robot arm. How can I fix that error?
  2 Commenti
Matt J
Matt J il 18 Dic 2021
Please post code in code wells like this:
a=1;
b=2;
Irem ERSIN
Irem ERSIN il 18 Dic 2021
Theta1 = (app.Theta1EditField.Value)*pi/180;
Theta2 = (app.Theta2EditField.Value)*pi/180;
Theta3 = (app.Theta3EditField.Value)*pi/180;
Theta4 = (app.Theta4EditField.Value)*pi/180;
Theta5 = (app.Theta5EditField.Value)*pi/180;
Theta6 = (app.Theta6EditField.Value)*pi/180;
L_1 = 0;
L_2 = 80;
L_3 = 70;
L_4 = 50;
L_5 = 0;
L_6 = 0;
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]);
L(4) = Link([0 0 L_4 -pi/2]);
L(5) = Link([0 0 L_5 pi/2]);
L(6) = Link([0 L_6 0 0]);
Robot = SerialLink(L);
Robot.name = 'Six_R_Robot';
% Robot.plot([Theta1 Theta2 Theta3 Theta4 Theta5 Theta6]);
T = Robot.fkine([Theta1 Theta2 Theta3 Theta4 Theta5 Theta6]);
num2str(floor(T.t(1))) = app.xEditField.Value;
num2str(floor(T.t(2))) = app.yEditField.Value;
num2str(floor(T.t(3))) = app.zEditField.Value;

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 18 Dic 2021
In MATLAB, the form
A(stuff) = B
can have two different meanings.
In the case that stuff evaluates to a symbolic variable or vector of symbolic variables, then it would create a symbolic function named A whose parameters were the symbolic variable(s) and whose body is the result of evaluating the right hand side. For example
syms x
f(x) = sin(x) + x^2
is the same as
syms x
f = symfun(sin(x) + x^2, x)
Otherwise, when stuff is not symbolic then
A(stuff) = B
means that if a variable in scope named A already exists, then its values at the indices in stuff are to be assigned whatever is in B. If no variable in scope exists then A is to be created as a variable first and given the same types as B, and then the assignment is to take place.
So where you have
num2str(floor(T.t(1)) = something
that would mean that a variable named num2str should be created and should be indexed at location given by floor(T.t(1)) and that location is to be assigned whatever is on the right.
If the result of floor() were all positive integers then the indexing would be valid and the assignment could take place. But if the results floor() was 0 or negative then the assignment would fail.
It is highly likely that the reader will get confused by assignments to a variable named num2str and that is to be avoided.
  2 Commenti
Walter Roberson
Walter Roberson il 18 Dic 2021
I think you might have left and right sides reversed! A=B evalutes B and assigns into A; I think you expected the left side to be assigned to the right.
Walter Roberson
Walter Roberson il 18 Dic 2021
Note that edit fields in app designer can be created as numeric, in which case you would assign their Value property a numeric value instead of a string or character vector

Accedi per commentare.

Più risposte (1)

Matt J
Matt J il 18 Dic 2021
You must examine the contents of floor(T.t(3)). It is zero, which is not a valid index.

Categorie

Scopri di più su Simulation 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