Filter löschen
Filter löschen

Index not working - very simple problem!

3 Ansichten (letzte 30 Tage)
Catriona Fyffe
Catriona Fyffe am 22 Jul. 2020
Kommentiert: Stephen23 am 22 Jul. 2020
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.

Akzeptierte Antwort

madhan ravi
madhan ravi am 22 Jul. 2020
idx = abs(INSW - 3) < 1e-2; set tolerance
  1 Kommentar
Catriona Fyffe
Catriona Fyffe am 22 Jul. 2020
Nice that's brilliant and works, thank you!! I thought I was going mad.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Bruno Luong
Bruno Luong am 22 Jul. 2020
Bearbeitet: Bruno Luong am 22 Jul. 2020
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 Kommentar
Catriona Fyffe
Catriona Fyffe am 22 Jul. 2020
Ok thanks also for this info, I'll look out for that in future!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by