Fill in a matrix after an evaluation

1 回表示 (過去 30 日間)
ILIANNE GUILLOT VIDAL
ILIANNE GUILLOT VIDAL 2021 年 4 月 26 日
I want to do a for loop in order to, with a matrix full of zeros of the specific size, calculate the vector error with the formula on d_right, knowing the values of x, y and z. Once I compute the code, this error shows up: "Unable to perform assignment because the left and right sides have a different number of elements". What should I be changing, is it the matrix full of zeros? Thank you in advance
accuracy_right = zeros(76,6)
for i = 1:1:76
data_def_x = target(:,i+1); %All x values
data_def_y = target(:,i+2); %All y values
data_def_z = target(:,i+3); %All z values
d_right = sqrt((data_def_x-x0_r).^2+(data_def_y-y0_r).^2+(data_def_z-z0_r).^2);
accuracy_right(i) = d_right;
end
  1 件のコメント
Rik
Rik 2021 年 4 月 26 日
i is a single value, and because the data_def variables are vectors, that means d_right is a vector. You're trying to store a vector in a single element.

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

採用された回答

Rik
Rik 2021 年 4 月 26 日
I guess boldly:
x0_r=rand;y0_r=rand;z0_r=rand;
target=rand(6,76+3);
accuracy_right = zeros(76,6);
for i = 1:1:76
data_def_x = target(:,i+1); %All x values
data_def_y = target(:,i+2); %All y values
data_def_z = target(:,i+3); %All z values
d_right = sqrt((data_def_x-x0_r).^2+(data_def_y-y0_r).^2+(data_def_z-z0_r).^2);
accuracy_right(i,:) = d_right;
% ^^
end
  1 件のコメント
ILIANNE GUILLOT VIDAL
ILIANNE GUILLOT VIDAL 2021 年 4 月 26 日
Thank you so much!!!!!!

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

その他の回答 (1 件)

minghuaa lu
minghuaa lu 2021 年 4 月 26 日
no data target x0_r y0_r z0_r
  1 件のコメント
ILIANNE GUILLOT VIDAL
ILIANNE GUILLOT VIDAL 2021 年 4 月 26 日
Yes, it is inserted before the loop

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by