Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

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

1 Ansicht (letzte 30 Tage)
Angela Marino
Angela Marino am 15 Jul. 2020
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
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 Kommentare
Tanmay Das
Tanmay Das am 15 Jul. 2020
Hi. Can you please elaborate on what is m?
Angela Marino
Angela Marino am 15 Jul. 2020
m is the time interval between f and f+1

Antworten (1)

Parth Dethaliya
Parth Dethaliya am 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.

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by