MATLAB Answers

Multiple left-hand sides must be separated by commas

105 views (last 30 days)
Hello
When I execute my code, the error message keeps popping up, "Multiple left-hand sides must be separated by commas" .
I don't know what to do to fix it.
I really thank you for your help!
for i = 1:10
EP(1,:)=EP1;
while abs(EP(i+1,:)-EP(i,:)) > 0.1 ; %[m]
t0(1) = ice;
for j = 1:4
a(j) = EP(i,1) - s(j,1); % X_total - X_satellite
b(j) = EP(i,2) - s(j,2); % Y_total - Y_satellite
c(j) = EP(i,3) - s(j,3); % Z_total - Z_satellite
R_t(j) = sqrt(a(j)^2+b(j)^2+c(j)^2); % R_total
PSR(j) = R_t(j) + c*t0(i);
end
Mat1(i) = [[a b c]./R_t c];
Mat2(i) = [PSR-R_t];
[dx(i); dy(i); dz(i); t0(i)] = inv(Mat1(i))*Mat2(i);
EP(i+1,1) = EP(i,1) + dx(i);
EP(i+1,2) = EP(i,2) + dy(i);
EP(i+1,3) = EP(i,3) + dz(i);
t0(i+1) = t0(i);
end

  3 Comments

Stephen Cobeldick
Stephen Cobeldick on 18 Sep 2020
Just like the error message states, this
[dx(i); dy(i); dz(i); t0(i)] = ...
% ^ ^ ^ outputs must be separated by commas!
is not valid MATLAB syntax. It looks like you are trying to do some kind of implicit "unpacking", but in fact the output of your numeric operation mtimes is one numeric array, not four separate output arguments.
Mat1(i) = [[a b c]./R_t c]; % if the RHS is non-scalar then this line will throw an error.
Mat2(i) = [PSR-R_t]; % both of thse lines have superfluous square brackets too.
Given that Mat1(i) is scalar, what is the point in taking its matrix inverse?
Given that you do not refer to previous elements of Mat1 and Mat2, why do you need to index into them at all?
If you are trying to solve systems of equations then use mldivide or mrdivide (read the inv documentation to know why).
Postit123
Postit123 on 18 Sep 2020
Thank you very much. I modify them!
Now I have other error, Index in position 1 exceeds array bounds (must not exceed 1) for this line. Could you explain what the problem is?
while abs(EP(i+1,:)-EP(i,:)) > 0.1
Stephen Cobeldick
Stephen Cobeldick on 18 Sep 2020
"Could you explain what the problem is?"
You are trying to access a row of EP that does not exist.
Look at the size of EP:
size(EP)
and the value of i+1:
disp(i+1)
Does EP have an i+1 row?

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 18 Sep 2020
[dx(i); dy(i); dz(i); t0(i)] = inv(Mat1(i))*Mat2(i);
You need to use comma instead of semicolon there.
But it is not going work. You need to assign the result to a variable and then index the variable to pull out parts to assign to those variables.
You are also going to need to start using cell arrays for Mat1 and Mat2
Is there a reason that you are storing the Mat1 and Mat2 results? You do not appear to be using them after the loop.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!