Hi.
I don't know how to solve this. I have this code
for i= 1:19
[x(i),y(i),z(i)] = multilaterasi(Reader(1, 1), Reader(1, 2), Reader(1, 3), Distance(1,i), Reader(2, 1), Reader(2, 2), Reader(2, 3), Distance(2,i), Reader(3, 1), Reader(3, 2), Reader(3, 3), Distance(3,i), Reader(4, 1), Reader(4, 2), Reader(4, 3), Distance(4,i));
end
I want to calculate the MSE from that code below with this formula.
MSE = sqrt((x(i)-xa)^2+(y(i)-1)^2+(z(i)-1.5)^2)
x(i), y(i), and z(i) should looping with for 1:19. But xa should looping with step 2 (the result should be 2,4,6,8,10,12 until 38). For example:
MSE = sqrt((x(1)-2)^2+(y(1)-1)^2+(z(1)-1.5)^2)
MSE = sqrt((x(2)-4)^2+(y(2)-1)^2+(z(2)-1.5)^2)
MSE = sqrt((x(3)-6)^2+(y(3)-1)^2+(z(3)-1.5)^2)
and the same for the rest until x(19), y(19), z(19) and xa=38
Please help. Thank you

 Accepted Answer

In your code, ‘x’, ‘y’, and ‘z’ are vectors. You do not need a loop, since MATLAB uses vectorised operations and will do this automatically.
This works:
MSE = sqrt((x-xa).^2+(y-1).^2+(z-1.5).^2);
Here, since the argument vectors are row vectors, ‘MSE’ will be a row vector the same size as the argument vectors.

2 Comments

oh right thank you
My pleasure.

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!