Info

此问题已关闭。 请重新打开它进行编辑或回答。

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

1 次查看(过去 30 天)
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

回答(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.

标签

Community Treasure Hunt

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

Start Hunting!

Translated by