필터 지우기
필터 지우기

Turning a 2x80 to an 80x80

조회 수: 2 (최근 30일)
Christian Basa
Christian Basa 2021년 4월 16일
댓글: Les Beckham 2021년 4월 17일
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.

답변 (1개)

Les Beckham
Les Beckham 2021년 4월 16일
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
Les Beckham
Les Beckham 2021년 4월 17일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by