Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

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

1 view (last 30 days)
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

Answers (1)

Parth Dethaliya
Parth Dethaliya on 15 Jul 2020
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.

This question is closed.

Community Treasure Hunt

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

Start Hunting!