How can I operate with a for loop on a two-dimensional matrix?

2 ビュー (過去 30 日間)
studentmatlaber
studentmatlaber 2022 年 4 月 21 日
コメント済み: David Hill 2022 年 4 月 21 日
Hello to everyone. There are matrices named X1 and Y1. Both are 3x109 in size. What I want to do here is to calculate the MEAN ABSOLUTE ERROR value of each row of these two matrices and save it in a matrix of size MAE=3x1.
To elaborate a little more, I'm saving the first rows of both matrices in an intermediate vector (BX and BY). I keep all the elements of these BX and BY vectors in the MAE operation and save them in the first row and column of the MAE vector. Then the same process should be done again for the 2nd row and the 3rd row. I wrote such a code, but I am not getting the correct result. I would be glad if you help.
x_T=0.3;
y_T=0.3;
for n=1:size(x1,1)
BX=x1(n,:);
BY=y1(n,:);
for m=1:size(x1,2)
mae(n)=sum(sqrt((BX(m) - x_T).^2 + (BY(m) - y_T).^2));
end
end
  2 件のコメント
Les Beckham
Les Beckham 2022 年 4 月 21 日
What are x_T and y_T?
studentmatlaber
studentmatlaber 2022 年 4 月 21 日
I editted

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

回答 (1 件)

David Hill
David Hill 2022 年 4 月 21 日
編集済み: David Hill 2022 年 4 月 21 日
x_T=0.3;y_T=0.3;
mae=sum(hypot(x-x_T,y-y_T),2);
  2 件のコメント
studentmatlaber
studentmatlaber 2022 年 4 月 21 日
Yes, I need to fix this as well. But the main problem is saving inside the for loop. The MAE value obtained from each vector BX(1,:) and BY(1,:) should be written in MAE(1,1).
David Hill
David Hill 2022 年 4 月 21 日
No need for a for-loop. Just run the code above.

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

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by