Info

This question is closed. Reopen it to edit or answer.

I have matrix with "L" row and "N" column(L<N). I want to convert this matrix to N*N matrix. how can I do it in matlab?

1 view (last 30 days)
Hello all, I having quite a bit of difficulty with some operator of matrixes.
assume "L "and "N" are arbitrary constant values and L<N.
I have (L-2*N-2)matrix and I want to sum this matrix with a (N-2*N-2)matrix so I need that two matrix have a equal dimension.
In my work I need to sum these two matrices. Can you help me with this??
for example A(3,5) and B(5*5)
and I need A+B.
How can I have these two matrices with equal dimensions?
  4 Comments
David Hill
David Hill on 23 Nov 2019
If the number of elements in each matrix do not match, you cannot reshape them so they can be added. You could pad the small matrix with zeros or delete elements from the larger matrix, but you are the one that must decide.
Image Analyst
Image Analyst on 23 Nov 2019
Again, please give full example of inputs and output. Provide us small matrices of width 5 or 10. I also think you might want to read this link

Answers (1)

Steven Lord
Steven Lord on 23 Nov 2019
There are many ways to expand a matrix. Let's take one small example.
A = [1 2 3; 4 5 6];
A is 2-by-3. If I wanted to make this a 4-by-3, which of the following would you want? Or is there another alternative?
z = zeros(1, 3);
n = NaN(1, 3);
A1 = [z; z; A]
A2 = [z; A; z]
A3 = [A; z; z]
A4 = [n; n; A]
A5 = [n; A; n]
A6 = [A; n; n]
A7 = repmat(A, 2, 1)
A8 = repelem(A, 2, 1)

Products


Release

R2015a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!