フィルターのクリア

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 Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by