필터 지우기
필터 지우기

Remove Certain Values in Matrix

조회 수: 3 (최근 30일)
Ben
Ben 2022년 9월 21일
답변: Chunru 2022년 9월 21일
Hi All,
I have a 8x6 matrix called Vel. Each Column contains one zero value, which is kind of a cutt off. What I want to do is set all the values in the column below the zero value to zero. So I should end up with a matrix that looks like this.
1 3 6 22 25 33
11 12 15 12 15 67
1 32 21 4 25 3
11 12 5 33 15 7
11 32 6 2 25 33
1 0 0 0 12 22
0 0 0 0 0 0
0 0 0 0 0 0
I tried a few things using the index values for the zeroes but I wasn't able to solve the problem and ended up kind of going round in circles. Is there an easy way to achieve this???
Code is below:
Vel = [1,3,6,22,25,33; 11,12,15,12,15,67; 1,32,21,4,25,3; 11,12,5,33,15,7; 11,32,6,2,25,33; 1,0,0,0,12,22; 0,31,6,4,0,0; 12,6,5,5,8,7 ]
Vel = 8×6
1 3 6 22 25 33 11 12 15 12 15 67 1 32 21 4 25 3 11 12 5 33 15 7 11 32 6 2 25 33 1 0 0 0 12 22 0 31 6 4 0 0 12 6 5 5 8 7
index = find(Vel==0)
index = 6×1
7 14 22 30 39 47

채택된 답변

Chunru
Chunru 2022년 9월 21일
Vel = [1,3,6,22,25,33;
11,12,15,12,15,67;
1,32,21,4,25,3;
11,12,5,33,15,7;
11,32,6,2,25,33;
1,0,0,0,12,22;
0,31,6,4,0,0;
12,6,5,5,8,7 ];
for i=1:width(Vel)
idx = find(Vel(:,i)==0, 1, 'first');
Vel(idx:end, i)=0;
end
Vel
Vel = 8×6
1 3 6 22 25 33 11 12 15 12 15 67 1 32 21 4 25 3 11 12 5 33 15 7 11 32 6 2 25 33 1 0 0 0 12 22 0 0 0 0 0 0 0 0 0 0 0 0

추가 답변 (0개)

카테고리

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