Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

Is there a way to replace a specific NaN elements by integer where isnan would not work with steps greater than 1?

1 visualizzazione (ultimi 30 giorni)
Hello All,
Could you please help with this problem
I have this matrix
hh=[NaN 1 2 3 4;3 5 66 NaN 6;NaN 3 4 7 NaN; 9 NaN 8 2 NaN];
and I want to replace only the NaN in some places to an integer. I have tried this hh(isnan(hh(1:2:4,1)))=1; which should replace the NaN in element (3,1) by 1 but did not work

Risposte (1)

Walter Roberson
Walter Roberson il 4 Lug 2017
mask = isnan(hh(:, 1)); mask(2:2:end) = false;
hh(mask) = 1;

Questa domanda è chiusa.

Community Treasure Hunt

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

Start Hunting!

Translated by