How do I resize a matrix in MATLAB?
Suppose I had a 1-by-12 matrix and I wanted to resize it to a 4-by-3 matrix. How could I do this?
My current solution is kind of ugly:
for n = 1:(length(mat)/3) out(n,1:3) = mat( ((n-1)*3 + 1):((n-1)*3 + 3) );
Is there a better way to do this?
NOTE:-
Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help , Finance Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.Answers:
reshape
is of course the proper solution, as stated by @gnovice.A nice feature of
reshape
is that it allows this:
A = 1:12; B = reshape(A,4,[]); B = 1 5 9 2 6 10 3 7 11 4 8 12So if you don't know how many columns there will be,
reshape
will compute it for you. Likewise,reshape
will fill in the number of rows, if you leave that out.SEE COMPLETE ANSWER CLICK THE LINKhttps://matlabhelpers.com/questions/how-do-i-resize-a-matrix-in-matlab-.php
Comments
Post a Comment