フィルターのクリア

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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by