Zero out values from a specific row in a matrix
조회 수: 4 (최근 30일)
이전 댓글 표시
I create a matrix, I need to reset all values above or below a certain line
c = randi([50 90],1,900); % rows in the matrix before or after which you need to reset everything
x = rand(100,900);
I would appreciate any help
댓글 수: 1
Jan
2022년 2월 24일
Does "reset" means, to set the value to 0? A small example with inputs and output would clarify this.
채택된 답변
DGM
2022년 2월 24일
Depends if you want before or after. Since there's no specified mechanism to determine which, I'm assuming they're separate cases.
% a smaller array
sz = [10 10];
c = randi(round([0.5 0.9]*sz(1)),1,sz(2))
x = rand(sz);
% above
xa = zeros(sz);
for col = 1:sz(2)
xa(c(col):end,col) = x(c(col):end,col);
end
xa
% below
xb = zeros(sz);
for col = 1:sz(2)
xb(1:c(col),col) = x(1:c(col),col);
end
xb
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!