Compare each element of a matrix with each element of a vector
Información
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Mostrar comentarios más antiguos
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 comentarios
Tanmay Das
el 15 de Jul. de 2020
Hi. Can you please elaborate on what is m?
Angela Marino
el 15 de Jul. de 2020
Respuestas (1)
Parth Dethaliya
el 15 de Jul. de 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.
1 comentario
Angela Marino
el 15 de Jul. de 2020
La pregunta está cerrada.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!