Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Index exceeds the number of array elements (1)

1 Ansicht (letzte 30 Tage)
Ben Nolan
Ben Nolan am 24 Mär. 2020
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
function [] = diggerangle(L_12, L_23, L_13, x)
iteration_limit = 20;
tolerance = 10^-7;
x = [x(1)*(pi/180);x(2)*(pi/180)];
for count = 1:iteration_limit + 1
if count == iteration_limit + 1
error('Iteration limit reached. Iteration did not converge.')
end
f = [L_12*cos(x(1))-(L_13)-L_23*cos(x(2));...
L_12*sin(x(1))-L_23*sin(x(2))];
if abs(f)<tolerance
break
end
df = [-L_12*sin(x(1))+L_23*sin(x(2));...
L_12*cos(x(1))-L_23*cos(x(2))];
x = x - inv(df)*f;
end
x(1);
x(2);
x(1)*(180/pi)
x(2)*(180/pi)
end
  2 Kommentare
Ameer Hamza
Ameer Hamza am 25 Mär. 2020
How are you calling this function. Which line is giving this error?
Ben Nolan
Ben Nolan am 25 Mär. 2020
line 6: x = [x(1)*(pi/180);x(2)*(pi/180)];
this is the problem it is giving me the error: Index exceeds the number of array elements (1)

Antworten (1)

the cyclist
the cyclist am 25 Mär. 2020
You didn't answer Ameer's first question, but it seems clear that when you call the function
diggerangle(L_12, L_23, L_13, x) % what are the inputs here?
that the value of x is simply a scalar, and not a vector. Therefore,
x(2)
is going to give an error, because x only has one element.

Community Treasure Hunt

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

Start Hunting!

Translated by