Effacer les filtres
Effacer les filtres

Remove Certain Values in Matrix

3 vues (au cours des 30 derniers jours)
Ben
Ben le 21 Sep 2022
Réponse apportée : Chunru le 21 Sep 2022
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

Réponse acceptée

Chunru
Chunru le 21 Sep 2022
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

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by