hello everyone, I have a vector composed of 34 rows by 40 columns, I would like to calculate the average value of each row (therefore a 34x1) and then find the column of the starting vector that is closest to that column made up of average values, to then be able to find the corresponding column number . how can do it? thanks
my array name is veT:
for i = 1: duration
traci.simulation.step();
if i==1
for f=1:length(semafori)
traci.trafficlights.setPhaseDuration(semafori{f}, nominali(f,1))
end
end
for n=1:length(induction)
vec_sec(n,i)=traci.inductionloop.getLastStepVehicleNumber(induction{n});
end
for v=1:length(k)
if i==t(v)
for j=1:length(vec_sec(:,1))
veT(j,v)=sum(vec_sec(j,(t(v)-(T-1)):t(v))); % this is vector by34x40
end
for f=1:length(semafori)
traci.trafficlights.setPhase(semafori{f},0);
traci.trafficlights.setPhaseDuration(semafori{f},nominali(f));
end
end
end
end
traci.close

 채택된 답변

Torsten
Torsten 2022년 3월 12일

0 개 추천

[m,i] = min(vecnorm(veT-mean(veT,2)))

댓글 수: 5

thanks for the answer, where should I put that line of code? out of all end? the i that would be saved to me in the workspace, would then be the one in the column most similar to the average? Thank you
Torsten
Torsten 2022년 3월 12일
편집: Torsten 2022년 3월 12일
I don't know where to place the command.
Your question was that you have a (34x40) matrix, so you should place the command in your code after the matrix is formed - so most probably out of all at the end. And yes, the "i" refers to the column which is most similar to the average column (if you measure "similarity" by the 2-norm of the difference of the columns with the average column).
and then "m" instead what would it correspond to?
Torsten
Torsten 2022년 3월 12일
This is the minimum value itself, i.e. the minimum 2-norm of the difference between the columns and the average column.
thank you so much!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2022년 3월 12일

댓글:

2022년 3월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by