how to extract all values in array after certain value?

58 Ansichten (letzte 30 Tage)
nines
nines am 17 Jun. 2022
Kommentiert: nines am 17 Jun. 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?

Akzeptierte Antwort

Karim
Karim am 17 Jun. 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

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by