How to create a 3D matrix from the rows a 2D matrix without using loops
Show older comments
Here is my problem: Initially, I have an M matrix (252x4). I need to create a W matrix (252x4x252). The restrictions are:
- The elements in the third dimension of matrix W are 252 copies of the lines of matrix M. That is, the matrix corresponding to W(:,:, 1) is equivalent to repmat(M(1,:),[252 1]) The matrix corresponding to W(:,:,2) is equivalent to repmat (M(2,:),[252 1]) . . . The matrix corresponding to W (:,:, end) is equivalent to repmat (M (end,:), [252 1]) and so on.
- cannot use for loop or similar.
Is there any way to do linear transformations or using the repmat function to compose the W matrix without using loop?
2 Comments
James Tursa
on 28 Jan 2021
What have you tried so far? Does your homework assignment specifically forbid any other functions? Or just forbids loops?
paulocir
on 28 Jan 2021
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements 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!