如何使用Big Matrices为Matlab的saveas选择Formattype?

时间:2016-03-14 12:40:16

标签: matlab image-processing matrix

我正在尝试将输入矩阵大小增加10 ^ 3,并发现Matlab的saveas命令不再适用于我当前的设置

saveas(imgRGB, filenamePng)

错误

217     saveas(imgRGB, filenamePng);
Error using saveas (line 58)
Invalid handle.

Error in masi (line 217)
    saveas(imgRGB, filenamePng);

 function saveas( h, name, format )
 ↑
Error: Function definitions are not permitted in this context.

我可以通过imshow(imgRGB)正确地绘制图像,因此它表明saveas本身及其设置有问题。 我调查了内存,发现这部分是在第57行的命令saveas中给出错误

if ~all(ishandle(h))
    error('MATLAB:saveas:invalidHandle','%s',...
        getString(message('MATLAB:saveas:invalidHandle')))
end

我不理解这种行为,因为它取决于您为命令提供的矩阵的大小。 我认为避免它的唯一方法是明确定义第三个参数,如

saveas(imgRGB, filenamePng, formattype)

我没有成功saveas(imgRGB, filenamePng, 'png')提供输出

217     saveas(imgRGB, filenamePng, 'png');
Error using saveas (line 58)
Invalid handle.

Error in masi (line 217)
    saveas(imgRGB, filenamePng, 'png');

我想我可能需要将输出格式从.png改为.eps(EPS Level 3 Black and White),这可能更适合科学计算,因为我只需要大约1024种灰色。 但是,执行..., 'eps')会产生与上一个命令相同的错误。

代码

dpi=100;
diffTime = timeEndSeconds - timeStartSeconds; 
N=361; 
unitsPerInches = [0 0 15 15];

hFig=figure('Visible', 'off', ...
    'Units', 'inches', 'Position', unitsPerInches);

time=linspace(timeStartSeconds, timeEndSeconds, diffTime*N);
imagesc(time, potential, matrix); 
set(gca, ...
    'color','none', ... % no background
    'position', unitsPerInches*dpi^1,'units','normalized' ... 
    ); 
colormap(gray); % here many gray varieties
imgRGB = print(hFig, '-RGBImage', strcat('-r', num2str(dpi))); 
saveas(imgRGB, filenamePng, 'eps');

如何在Matlab中为大矩阵设置formattype和saveas?

2 个答案:

答案 0 :(得分:1)

如果您read the documentation,很明显如果您使用2个输入来致电saveas

  

saveas(fig,filename)保存图形或Simulink®框图   由fig指定为文件名。

因此,如果要保存Simulink块,请使用2个参数调用它,否则使用3。

答案 1 :(得分:1)

在Matlab中有两种保存图像的方法。

  1. 你有一个RGB数组(尺寸:imageHeight * imageWidth * 3),和 您使用imwrite(rgbImage,fileName)
  2. 将其写入磁盘
  3. 您将其绘制在图形(imshowimagesc)中,然后打印图形 提交{saveas(figureHandle, fileName),其中figureHandle是 标量)。这两种方式都不应受可变大小的限制。