How would I transform a 5-dimensional vector into a 3-dimensional vector?
Show older comments
How would I transform a 5-dimensional vector into a 3-dimensional vector? An example would be very helpful, but I really do not know how to do this.
Answers (1)
How you would do it depends on how you want it to work.
For instance, if your 5-dimensional matrix contains two singleton (i.e., of size 1) dimensions that you want to remove, you could use squeeze():
X = randn(5,1,3,1,2);
Y = squeeze(X);
disp(X);
disp(Y);
Or you could use reshape() in that same situation:
Y = reshape(X,[5 3 2]);
disp(Y);
Or even if there are no singleton dimensions, you could use reshape(), but you have to specify how you want this reshaping done:
X = randn(5,2,3,4,2);
disp(X);
Y = reshape(X,[10 12 2]);
disp(Y);
Y = reshape(X,[5 6 8]);
disp(Y);
Y = reshape(X,[5 2 24]);
disp(Y);
permute() and shiftdim() might also be useful.
2 Comments
Connor Mondock
on 4 Feb 2022
Voss
on 4 Feb 2022
All of these examples use built-in functions.
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!