简体   繁体   English

matlab2tikz错误绘制带有alphadata的图像

[英]matlab2tikz error plotting image with alphadata

I am plotting a matrix ("I1") which has some NaN values through imagesc command. 我正在绘制一个通过imagesc命令具有一些NaN值的矩阵(“ I1”)。 As you can see in the code I have set that such NaN values should be plotted in white 正如您在代码中看到的那样,我已将此类NaN值绘制为白色

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: 我需要在matlab2tikz中转换此类图像(请参见脚本的最后一行),但出现以下错误:

Error using writepng>parseInputs (line 349) The value of 'alpha' is invalid. 使用writepng> parseInputs时出错(第349行)'alpha'的值无效。 Expected input to be one of these types:double, uint8, uint16 预期输入为以下类型之一:double,uint8,uint16

Instead its type was logical. 相反,它的类型是合乎逻辑的。

Can someone help to overcome this problem? 有人可以帮助克服这个问题吗? Thanks in advance 提前致谢

All you have to do is convert your the transparencies into double . 您要做的就是将透明胶片转换为double Right now, the array is of type logical and transparency data can only be one of double, uint8 or uint16 . 现在,该数组是logical类型的,并且透明度数据只能是double, uint8uint16 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 . 给定数组的性质,您希望非NaN任何内容都完全可见,而NaN值透明,因此您想要0/1数据,而不是true/false

Simply convert to double after the fact: 简单地转换为事实后的double

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM