필터 지우기
필터 지우기

Find index where value exceeds threshold

조회 수: 277 (최근 30일)
Martin Pott
Martin Pott 2014년 8월 7일
댓글: Image Analyst 2018년 2월 11일
Dear all,
I want to be able to find indices where values exceed a certain threshold. So if my variable of interest is called 'returns' and is formatted in a t x n matrix, I would like to find all indices in 'returns' that exceed a value X.
I'm working on a project that uses in- and out-of-sample stock returns to check the expediency of my model. Therefore, I don't want to just delete return outliers, but check manually if they make sense.
Thanks in advance.

답변 (2개)

Andrew Reibold
Andrew Reibold 2014년 8월 7일
편집: Andrew Reibold 2014년 8월 7일
This should answer your problem! :-)
idx = find(returns > X)
Now if you have an MxN matrix, the idx returned is the single index number as if you concatenated all the rows.
Do you need help turning it into two index numbers? I can do that too.
  댓글 수: 4
Yoni Sher
Yoni Sher 2018년 2월 11일
Isn't 'find' inefficient? is there some other function that is better?
Image Analyst
Image Analyst 2018년 2월 11일
No. Use tic and toc to time it and you'll see it's plenty fast enough for you.

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2014년 8월 7일
Look at this simple example:
m=magic(4) % Sample data
linearIndexes = find(m>8) % Find elements with value more than 8
[rows, columns] = ind2sub(size(m), linearIndexes)
In the command window:
m =
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
linearIndexes =
1
3
6
8
10
12
13
15
rows =
1
3
2
4
2
4
1
3
columns =
1
1
2
2
3
3
4
4

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by