deleting of rows in a matrix
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Omer Utku Altindag
le 4 Mai 2021
Commenté : Omer Utku Altindag
le 4 Mai 2021
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
0 commentaires
Réponse acceptée
Cris LaPierre
le 4 Mai 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),:)
% Alternate - delete the rows that are not wanted
A(~ismember(A(:,1),B),:)=[]
5 commentaires
Steven Lord
le 4 Mai 2021
I would use ismembertol instead of ismember to account for floating point arithmetic.
x = 0.1;
y = x + x + x; % 0.3 right?
isPoint3 = y == 0.3 % false, y is close but not exactly 0.3
difference = y - 0.3 % very small
ismember(y, 0.3) % false, not exactly equal
ismembertol(y, 0.3) % true, it's close enough
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical 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!