# Turning a 2x80 to an 80x80

5 views (last 30 days)
Christian Basa on 16 Apr 2021
Commented: Les Beckham on 17 Apr 2021
I was wondering how I could change the size of a matrix that already contains values by adding zeros, but still keeping those values the same. I'm just trying to expand the matrix, not match it to the size of another. Anything helps.

VBBV on 16 Apr 2021
%if true
A = rand(2,80);
AA = zeros(78,80);
AAA = [A;AA];

Les Beckham on 16 Apr 2021
It really depend on how you want to expand the matrix.
If I understand what you want, you could try something like this:
initial = reshape(1:160,[2,80]);
final = zeros(80,80);
final(1:size(initial,1), 1:size(initial,2)) = initial;
final
##### 1 CommentShowHide None
Les Beckham on 17 Apr 2021
Actually, the easiest way to do this is probably to use the way that Matlab expands a matrix when you assign to an element that doesn't exist yet (by filling with zeros).
initial = reshape(1:160,[2,80]); % some initial values 2x80
final = initial; % copy the initial values
final(80, 80) = 0; % expand the final array to 80x80, filling with zeroes