Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Compare each element of a matrix with each element of a vector

1 回表示 (過去 30 日間)
Angela Marino
Angela Marino 2020 年 7 月 15 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hello everyone! I would like to compare each element of the "distance" matrix with each element of the "pos_R2" vector. If the compared values ​​are equal I want to keep the value of the instant i in the vector check_point. Instead, if f is greater than one I want to calculate the average value between f and f-1.
%load variables
load simulazioe_1.m
for i=1:7200
for j=1:4
if distanza(i,j)==pos_R2(:,1)
check_point(1,1)=1;
if f>1
veloc_ML(m,j)=mean(veloc(check_point(f-1,j):check_point(f,j),j));
pers_ML(m,j)=mean(num_persone(check_point(f-1,j):check_point(f,j),j));
end
f=f+1;
end
end
end
However this code does not work. How could I do? thank you
  2 件のコメント
Tanmay Das
Tanmay Das 2020 年 7 月 15 日
Hi. Can you please elaborate on what is m?
Angela Marino
Angela Marino 2020 年 7 月 15 日
m is the time interval between f and f+1

回答 (1 件)

Parth Dethaliya
Parth Dethaliya 2020 年 7 月 15 日
load simulazione_1.mat
for i=1:7200
for j=1:4
if any(pos_R2(:,1 == distanza(i,j))) %Adding any() would do your job
check_point(i,j)=1; % Changed from (1,1) to (i,j) but it may depend on your requirement
if f>1
veloc_ML(m,j)=mean(veloc(check_point(f-1,j):check_point(f,j),j));
pers_ML(m,j)=mean(num_persone(check_point(f-1,j):check_point(f,j),j));
end
f=f+1;
end
end
end
You have not stated what is m exactly but i belive it is the index where distance matrix matches with pos_R2 vector. Please specify m and additional query if still you are facing problem.
  1 件のコメント
Angela Marino
Angela Marino 2020 年 7 月 15 日
m is the time interval between f and f+1

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by