Change zeros to Nans only at a certain page in a 3D matrix
1 view (last 30 days)
Show older comments
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;
0 Comments
Accepted Answer
More Answers (1)
dpb
on 2 Jul 2020
Edited: dpb
on 3 Jul 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 Comments
dpb
on 3 Jul 2020
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.... :(
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!