how to extract all values in array after certain value?

63 visualizaciones (últimos 30 días)
nines
nines el 17 de Jun. de 2022
Comentada: nines el 17 de Jun. de 2022
Hello!
I have an array where I am trying to extract all of the array between a set of numbers that are in the third column.
I have an array:
1 0 0
2 0 0
3 0 0
4 0 5000
5 0 0
6 0 0
7 0 0
8 0 5003
I want to extract:
4 0 5000
5 0 0
6 0 0
7 0 0
8 0 5003
I have tried:
third_row = array(:,3)==5000;
if third_row==5000;
find(array>third_row)
end
But I keep getting:
1 0 0
2 0 0
3 0 0
4 0 5000
5 0 0
6 0 0
7 0 0
8 0 5003
Do you have any suggestions?

Respuesta aceptada

Karim
Karim el 17 de Jun. de 2022
Hi,
Assuming that the part you need is between two random number, you can try the following:
Data = [1 0 0
2 0 0
3 0 0
4 0 5000
5 0 0
6 0 0
7 0 0
8 0 5003];
NonZero = find( Data(:,3) ~= 0 ); % get non-zero values
ExtractedData = Data( NonZero(1) : NonZero(2), :)
ExtractedData = 5×3
4 0 5000 5 0 0 6 0 0 7 0 0 8 0 5003
Otherwise if you need the values between two specific values, you can try the following:
StartIdx = find( Data(:,3) == 5000 );
StopIdx = find( Data(:,3) == 5003 );
ExtractedData = Data( StartIdx : StopIdx, :)
ExtractedData = 5×3
4 0 5000 5 0 0 6 0 0 7 0 0 8 0 5003
Hope it helps

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by