# how to extract all values in array after certain value?

40 views (last 30 days)
nines on 17 Jun 2022
Commented: nines on 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?
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Accepted Answer

Karim on 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
##### 1 CommentShowHide None
nines on 17 Jun 2022
amazing thank you!

Sign in to comment.

### Categories

Find more on Matrices and Arrays in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by