Vous suivez désormais cette soumission
- Les mises à jour seront visibles dans votre flux de contenu suivi
- Selon vos préférences en matière de communication il est possible que vous receviez des e-mails
nantowhite - Convert a 2D matrix into an image with NaNs replaced by white
USAGE:
[im, clim] = nantowhite(cvals)
[im, clim] = nantowhite(cvals, clim)
[im, clim] = nantowhite(cvals, clim, cmap)
nantowhite takes in an N x M matrix of values ('cvals') and outputs an N x M x 3 uint8 image that can be displayed on screen using 'image'. This function replaces 'imagesc' for situations where there are NaN values in the input matrix. Instead of displaying 'NaN' values using the first value in the colormap, it displays them using white. You can replace what would originally be 'imagesc(cvals)' with 'image(nantowhite(cvals))'.
This function was created because alpha layers used to make 'NaN' values transparent were ignored when images were saved in a vector format.
See the demo code below to get 'colorbar' to show the correct limits when using this function.
INPUT:
cvals - A 2D matrix to be converted to an image. Any NaN values in the
matrix will be converted into white pixels in the output image.
clim - The minimum and maximum value on the colorscale used for
converting values in 'cvals' into colors in the output image.
An empty maxtix is ignored. Positive or negative 'inf' values
are replaced by the minimum or maximum value in 'cvals'.
cmap - The color map to use for conversion from 'cvals' into colors.
OUTPUT:
im - An N x M x 3 uint8 image matrix. [N,M] = size(cvals)
clim - The color limits used when converting values to color pixels.
DEMO:
[X,Y] = meshgrid(-2*pi:pi/16:2*pi);
cvals = 20*cos(X).*sin(Y);
cvals(1:20,1:20) = NaN;
cvals(randperm(numel(cvals),400)) = NaN;
Original Code:
figure; ax = axes();
imagesc(cvals,'Parent',ax);
colorbar('Peer',ax);
Modified Code:
figure; ax = axes();
[im, cl] = nantowhite(cvals);
image(im,'Parent',ax,'CDataMapping','scaled');
set(ax,'CLim',cl);
colorbar('Peer',ax);
Citation pour cette source
Benjamin Kraus (2026). nantowhite (https://fr.mathworks.com/matlabcentral/fileexchange/41966-nantowhite), MATLAB Central File Exchange. Extrait(e) le .
Informations générales
- Version 1.0.0.0 (2,86 ko)
Compatibilité avec les versions de MATLAB
- Compatible avec toutes les versions
Plateformes compatibles
- Windows
- macOS
- Linux
| Version | Publié le | Notes de version | Action |
|---|---|---|---|
| 1.0.0.0 |
