for i = 1:duration
traci.simulation.step();
for n = 1: length(inductionID)
veicoliOGNIISTANTEsuInduction(n,i)=traci.inductionloop.getLastStepVehicleNumber(inductionID{n});
end
for v=1:length(k)
if i==t(v)
for n = 1: length(inductionID)
veicoliT(n,v)=sum(veicoliOGNIISTANTEsuInduction(n,(t(v)-(T-1)):t(v)));
end
newgreentime(:,v)=L*veicoliT(:,v); % L is a constant matrix
end
end
hi all, i have a vector n rows by v (whose columns are indexed). my vector newgreentime (:, v) in the considered v becomes a vector 4 x1, I would like to use this vector in a 3 dimensional vector 2x2xv how can I do it?

 채택된 답변

Walter Roberson
Walter Roberson 2022년 3월 1일

0 개 추천

newgreentime(:,:,v) = reshape(L*veicoliT(:,v), 2, 2); % L is a constant matrix
This assumes that you want the order
A B C D ->
[A C
B D]
if you need
[A B
C D]
then
newgreentime(:,:,v) = reshape(L*veicoliT(:,v), 2, 2).'; % L is a constant matrix

댓글 수: 4

thank you very much for the answer. A curiosity why to "reshape (L * vehiclesT (:, v), 2, 2). '" Why is there also that point near the closing parenthesis? it seems to work for what I want, however as soon as I can fully verify, thanks again
You have a vector of 4 elements. Compare
v = [1;2;3;4]
v = 4×1
1 2 3 4
reshape(v,2,2)
ans = 2×2
1 3 2 4
reshape(v,2,2).'
ans = 2×2
1 2 3 4
If you want adjacent elements in the vector to form columns, then do not use the .' but if you want adjacent elements in the vector to form rows, then you need the .' operator.
The .' operator is formally known as transpose:
transpose(reshape(v,2,2))
ans = 2×2
1 2 3 4
In general, if you have a vector v and you want to form an A by B matrix out of it, your choices are
reshape(v, A, B) %go down the columns
reshape(v, B, A).' %go across the rows
thank you so much. Because i have see that it works also with " ' " as well as " .' "
Voss
Voss 2022년 3월 2일
" .' " (dot single-quote) is transpose.
" ' " (single-quote) is complex conjugate transpose.
If the thing you are transposing (say X) contains only real values (i.e., no complex numbers), then X.' is the same as X'

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

질문:

2022년 3월 1일

댓글:

2022년 3월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by