Remove Certain Values in Matrix

6 次查看(过去 30 天)
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