Azzera filtri
Azzera filtri

Remove Certain Values in Matrix

3 visualizzazioni (ultimi 30 giorni)
Ben
Ben il 21 Set 2022
Risposto: Chunru il 21 Set 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

Risposta accettata

Chunru
Chunru il 21 Set 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

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by