Quo
Quo

Reputation: 61

matlab2tikz error plotting image with alphadata

I am plotting a matrix ("I1") which has some NaN values through imagesc command. As you can see in the code I have set that such NaN values should be plotted in white

I = magic(10);
I1 = NaN(10);
I1(4:6,4:6) = I(4:6,4:6);
f1 = figure();
h = imagesc(I1);
colormap jet;
set(h,'alphadata',~isnan(I1))
axis tight;
axis equal;
axis on;
matlab2tikz('file.tex')

I need to convert such image in matlab2tikz (see indeed last line of the script) but I obtain the following error:

Error using writepng>parseInputs (line 349) The value of 'alpha' is invalid. Expected input to be one of these types:double, uint8, uint16

Instead its type was logical.

Can someone help to overcome this problem? Thanks in advance

Upvotes: 1

Views: 284

Answers (1)

rayryeng
rayryeng

Reputation: 104545

All you have to do is convert your the transparencies into double. Right now, the array is of type logical and transparency data can only be one of double, uint8 or uint16. Given the nature of your array, you want anything that is non NaN to be fully visible while values that are NaN to be transparent, so you want 0/1 data, not true/false.

Simply convert to double after the fact:

set(h,'alphadata',double(~isnan(I1)));

Upvotes: 2

Related Questions