# deleting of rows in a matrix

2 views (last 30 days)
Hello Every one ;
I have an matrix that occurs with time step 0.0004 .And my step end time 0.312.But I want only the datas that 0.004 and multiples of 0.004. How can I write this code
For ex
[0.02 2 8
0.04 3 2
0.08 3 3
0.01 4 6
0.012 5 2
0.014 6 3
0.016 7 2] is existing and
[0.04 2 8
0.08 3 3
0.12 5 2
0.16 7 2] is that ı want

Cris LaPierre on 4 May 2021
I'd use a logical array (Ch 12 of MATLAB Onramp) created by ismember. I had to fix some values of A.
% Original matrix
A=[0.02 2 8
0.04 3 2
0.08 3 3
0.1 4 6
0.12 5 2
0.14 6 3
0.16 7 2];
% Desired steps
B=(0.04:0.04:0.16);
% Use logical indexing to extract just the desired rows
C = A(ismember(A(:,1),B),:)
C = 4×3
0.0400 3.0000 2.0000 0.0800 3.0000 3.0000 0.1200 5.0000 2.0000 0.1600 7.0000 2.0000
% Alternate - delete the rows that are not wanted
A(~ismember(A(:,1),B),:)=[]
A = 4×3
0.0400 3.0000 2.0000 0.0800 3.0000 3.0000 0.1200 5.0000 2.0000 0.1600 7.0000 2.0000
Omer Utku Altindag on 4 May 2021
Now the problem is fixed.Thank you both of you !!!

R2019b

### Community Treasure Hunt

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

Start Hunting!

Translated by