how do i change a matrix dimension from MxN to 100xN?
1 view (last 30 days)
Show older comments
Ganeshkumar M
on 28 Jun 2016
Edited: James Tursa
on 20 Sep 2023
Hi i have a matrix of size 46 x 1123 and i would want to expand it to a dimension of 100 x 1123. It will be best if the additional element rows are a copy of the original matrix as i will be using classify for subsequent manipulations.
Will be running this as a script hence the number of rows of 46 will differ from file to file but would want to standardise the output number of rows to 100. Thank you!
1 Comment
Image Analyst
on 28 Jun 2016
The 54 rows to tack on are not a multiple of 46 so exactly how were you planning on filling those rows? What rows from the original 46 are to be copied into the 54 new rows? And do you want to insert the rows at the top, or bottom or both? Have you read this link yet?
Accepted Answer
Jennifer Rebbin
on 20 Sep 2023
Starting in R2023b, you can use the paddata function to pad data by adding elements. For example, specify the size of the padded data and the pattern for adding elements.
A = rand(46,1123);
B = paddata(A,[100 size(A,2)],Pattern="circular")
0 Comments
More Answers (1)
the cyclist
on 28 Jun 2016
I have the same questions as Image Analyst asked, but here is my best guess as to what you want:
% Original matrix
A = rand(46,1123);
% New matrix
newRowCount = 100;
[m,n] = size(A);
B = zeros(newRowCount,n);
B = A(mod((1:newRowCount)-1,m)+1,:);
It fills in B from A row-by-row, repeating from the top of A if it reaches the bottom.
0 Comments
See Also
Categories
Find more on Matrices and Arrays 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!