필터 지우기
필터 지우기

how to extract all values in array after certain value?

조회 수: 33 (최근 30일)
nines
nines 2022년 6월 17일
댓글: nines 2022년 6월 17일
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?

채택된 답변

Karim
Karim 2022년 6월 17일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by