replacing values with nan does not work while other approaches work (nifti files)

2 vues (au cours des 30 derniers jours)
I have three very similar pieces of code that operate on two matrices. Firt two versions of the code work, while nan function does not and I am wondering why
Code aims to use indexes of chosen values in one matrix to remove elements of another. Specifically, I am working on neurological images and I am trying use a binary mask to remove non-brain space from another image.
Here is the code
% load the .nii result file (79x95x68 matrix)
PB = niftiread('/MATLAB Drive/Phonology 005.nii');
PB = PB(:);
% load a binary brain mask (79x95x68 matrix, 0 = non-brain space)
mask = niftiread("mask_overlap70_thr50.hdr","mask_overlap70_thr50.img");
mask = mask(:);
%% remove non-brain space from PB
% this method works and removes number of vector elements in half
PB(mask == 0) = [];
% this method to replace values also works
PB(mask == 0) = 5; % I can then drop values of 5 from PB
% this method does not work
PB(mask == 0) = nan;
I have double checked for nan values with isnan which returned a vector of 0s
So why does my nan function not work? I have found this approach from the forums
Thank you for your help

Réponses (1)

Steven Lord
Steven Lord le 23 Jan 2020
My suspicion is that PB is an array of one of the eight integer types. One of the things that page states about the integer types is "If you convert a NaN value into an integer class, the result is a value of 0 in that integer class."
myPB = ones(4, 'int8')
myPB(5) = NaN
Since an int8 array can't store NaN, element 5 of myPB is set to 0 instead.

Catégories

En savoir plus sur Convert Image Type dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by