I want to find the indices of a vector of shortwave radiation values which = 3 and replace them with 0. Should be simple.
My code is:
idx=INSW==3;
INSW(idx)=0;
I know there are 3s in the data, but sum(idx)=0. What on earth is going on?
I can even do
idx=INSW(122)==3 %I know there is a 3 here
but still idx=0.
If I look for 0s or other numbers instead the code works and finds them. I don't know if its something to do with the data format? It should be just double. Here's some screenshots of the data and problem. I have tried also using 3.0000 and 3.000000000000000.

 채택된 답변

madhan ravi
madhan ravi 2020년 7월 22일

0 개 추천

idx = abs(INSW - 3) < 1e-2; set tolerance

댓글 수: 1

Catriona Fyffe
Catriona Fyffe 2020년 7월 22일
Nice that's brilliant and works, thank you!! I thought I was going mad.

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

추가 답변 (1개)

Bruno Luong
Bruno Luong 2020년 7월 22일
편집: Bruno Luong 2020년 7월 22일

0 개 추천

Your 3 in array is actually not 3 but something like 3.0000000001 or other variant.
When you see MATLAB dispay with .0000 if often means that.

댓글 수: 1

Catriona Fyffe
Catriona Fyffe 2020년 7월 22일
Ok thanks also for this info, I'll look out for that in future!

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

카테고리

도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

2020년 7월 22일

댓글:

2020년 7월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by