Don't know how to Loop

3 ビュー (過去 30 日間)
Aulia   Pramesthita
Aulia Pramesthita 2017 年 12 月 19 日
コメント済み: Star Strider 2017 年 12 月 19 日
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

採用された回答

Star Strider
Star Strider 2017 年 12 月 19 日
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 件のコメント
Aulia   Pramesthita
Aulia Pramesthita 2017 年 12 月 19 日
oh right thank you
Star Strider
Star Strider 2017 年 12 月 19 日
My pleasure.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by