필터 지우기
필터 지우기

problem in matlab, I need help

조회 수: 1 (최근 30일)
yonatan friedman
yonatan friedman 2019년 1월 12일
댓글: Walter Roberson 2019년 1월 12일
insert a matrix with integers numbers : randi([-1,3],5,4)
3 2 -1 0
-1 1 0 2
0 3 -1 0
0 1 2 1
-1 2 3 3
I need the matrix after all the zeros will bubble up:
0 2 0 0
0 1 -1 0
3 3 -1 2
-1 1 2 1
-1 2 3 3
  댓글 수: 1
Walter Roberson
Walter Roberson 2019년 1월 12일
please use better titles . There was no way to guess anything about the topic of the question without opening it.

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

답변 (1개)

Image Analyst
Image Analyst 2019년 1월 12일
Here is one way:
m = randi([-1,3],5,4)
[rows, columns] = size(m);
mOutput = zeros(size(m));
for col = 1 : columns
thisCol = m(:, col);
zeroIndexes = thisCol == 0;
mOutput(sum(zeroIndexes)+1:end, col) = thisCol(~zeroIndexes);
end
mOutput % Report to the command window.

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by