Change zeros to Nans only at a certain page in a 3D matrix

I have a 3D matrix and I`m ttrying to change the zero elements of a certain page (let`s say the third one) to a NaNs. Can someone please help me? That one liner does not work.....
>> data(:,:,3)(data(:,:,3)==0)=NaN;

 Respuesta aceptada

cht
cht el 3 de Jul. de 2020
Editada: cht el 3 de Jul. de 2020
It should be:
a(2,2,4)=zeros;
isz=(a(:,:,3))==0;
a(isz,:,3)=nan
Still many thanks to @dbd for the help!

Más respuestas (1)

dpb
dpb el 2 de Jul. de 2020
Editada: dpb el 3 de Jul. de 2020
x(x(:,:,3)==0)=nan;
Start from inside out...above is
isZ=(x(:,:,3)==0);
x(isZ,3)=nan;
w/o the temporary indexing array.
ADDENDUM/ERRATUM: Missing trailing "3" added to original--dpb

3 comentarios

cht
cht el 3 de Jul. de 2020
Editada: cht el 3 de Jul. de 2020
It does change the first, but not the third page.
a(2,2,4)=zeros;
isz=a(:,:,3)==0;
a(isz)=NaN
a(:,:,1) =
NaN NaN
NaN NaN
a(:,:,2) =
0 0
0 0
a(:,:,3) =
0 0
0 0
a(:,:,4) =
0 0
0 0
>>
Oops. Missed adding the 3rd dimension when made the simplification...since the operation was
isZ=(x(:,:,3)==0)
isZ is 2D logical array -- x(isZ) --> same as x(isZ,1) without explicit 3rd dimension.
As the original shows, you have to address the plane of interest, too...edit'ed the Answer to correct.
Sorry for the typo...trying to clarify just confused.... :(
cht
cht el 3 de Jul. de 2020
Hi,
thanks for the fast response. But still I`m not sure that this works......
a(2,2,4)=zeros;
isz=(a(:,:,3))==0;
a(isz,3)=nan
a(:,:,1) =
0 0
0 0
0 0
0 0
a(:,:,2) =
NaN 0
NaN 0
NaN 0
NaN 0
a(:,:,3) =
0 0
0 0
0 0
0 0
a(:,:,4) =
0 0
0 0
0 0
0 0

Iniciar sesión para comentar.

Categorías

Preguntada:

cht
el 2 de Jul. de 2020

Editada:

cht
el 3 de Jul. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by