How to repeat elements of a matrix
Show older comments
Hello all, I am having a matrix of size 8 by 16.
My query is how to obtain 8 by 500 matrix from 8 by 16 matrix.
Any help is highly appreciated.
3 Comments
Jon
on 4 Apr 2023
I don't understand what you are trying to do. Please give an example. I can imagine that you are trying to do something like this
A = rand(8,16);
B = repmat(A,1,31);
but since 16 doesn't divide 500 you can't exactly get an 8 by 500 matrix, the above gives a 8 by 496 matrix, basically putting 31 copies of A side by side
charu shree
on 4 Apr 2023
Steven Lord
on 4 Apr 2023
Why not just pad your 8-by-16 array with 500-16 columns of NaN values?
x = reshape(1:8*16, [8 16]);
x(:, 17:500) = NaN;
Or fill in with random values:
x = reshape(1:8*16, [8 16]);
x(:, 17:500) = rand(8, 500-16);
What are the specific requirements for how you want the additional columns to be created?
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices 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!