Clear Filters
Clear Filters

transform vector in 2 dimensions into one in 3

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

Accepted Answer

Walter Roberson
Walter Roberson on 1 Mar 2022
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 Comments
Marco Carapellese
Marco Carapellese on 2 Mar 2022
thank you so much. Because i have see that it works also with " ' " as well as " .' "
Voss
Voss on 2 Mar 2022
" .' " (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'

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!