deleting of rows in a matrix
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Omer Utku Altindag
el 4 de Mayo de 2021
Comentada: Omer Utku Altindag
el 4 de Mayo de 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 comentarios
Respuesta aceptada
Cris LaPierre
el 4 de Mayo de 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 comentarios
Steven Lord
el 4 de Mayo de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!