0
votes

I have tried multiple solutions in matlab to convert a vector for example

A = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]

into

B= [ 1  2  3  4 ]
     5  6  7  8
     9  10 11 12
     13 14 15 16 
     17  0  0  0
      0  0  0  0
      0  0  0  0
      0  0  0  0

Here the desired matrix is 8x4 or rather the height or width is any multiple of 4. This would mean the nearest greater multiple of 4 if we keep any one dimension(height or width) fixed for fitting all elements and padding the extra elements with zeroes. I have tried reshape like so

reshape([c(:) ; zeros(rem(nc - rem(numel(c),nc),nc),1)],nc,[])

Here c is the original vector or matrix, nc is the number of columns.

It simply changes the number of rows and cols but does not take into account the possible powers required by the condition for height and width. I don't have the Communications Toolbox which has the vec2mat function. Another possible alternative thought is to initialize a matrix with all zeroes and then assign. But at this point I'm stuck. So please help me matlab experts.

1
How do you determine the number of rows? Your example does not use the nearest multiple of 4...beaker
What I mean is I get an original matrix A which is of arbitrary length. I try to convert it into a new matrix whose width or height can be fixed. For instance 4x4, 4x8, 4x12 and so on.Parth Sane
Ah, so the number of rows is a multiple of 4, not the number of elements. I see now.beaker
@beaker Do upvote the question if you think its good. I'm trying to get feedback whether the question was properly defined. On SO its really an art of asking questions.Parth Sane

1 Answers

1
votes

i think this what you mean:

n = 4;
A = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17];
B = zeros(n,ceil(numel(A)/n^2)*n);
B(1:numel(A)) = A;
B = B'

B = [ 1  2  3  4 
     5  6  7  8
     9  10 11 12
     13 14 15 16 
     17  0  0  0
      0  0  0  0
      0  0  0  0
      0  0  0  0]