Filter data conditionally based on previous row
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
James Browne
el 26 de Dic. de 2020
Respondida: Image Analyst
el 26 de Dic. de 2020
Hi,
I have an array of test data. I want to filter out conditionally rows which contain a value in one column that does not increase over the previous row.
I was able to do this in excel using the following if statement:
=IF(AND(AN9<=0,(AN9<AN8)),AQ9,IF(AND(AN9>=0,(AN9>AN8)),AQ9,NA()))
I think I essentially need it to return a logical value of zero if the value in the row of the column doesn't increase over the previous. A simplified example of what I want to do is:
1.0 5.0
1.3 6.0
3.1 3.0
2.0 2.0
1.9 6.0
1.8 7.0
2.4 8.0
3.5 1.0
would return:
1.3 6.0
3.1 3.0
2.4 8.0
3.5 1.0
Is there a way that I can perform something similar in Matlab?
Thanks for any help you can provide!
0 comentarios
Respuesta aceptada
Image Analyst
el 26 de Dic. de 2020
Try this. I think it's pretty self-explanatory.
m = [...
1.0 5.0
1.3 6.0
3.1 3.0
2.0 2.0
1.9 6.0
1.8 7.0
2.4 8.0
3.5 1.0 ]
col1Differences = [0; diff(m(:, 1))] % Get differences from one row to the next in column 1.
rowsToExtract = col1Differences > 0; % Get a logical vector of what rows have positive differences.
m2 = m(rowsToExtract, :) % Extract only those rows with a positive difference.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Statistics and Linear Algebra 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!