我有一个脚本将图像打印到文件.我希望我打印的文件的名称是动态的 - 即我希望输出文件名依赖于某些参数.有点像这样:
outputFileNames = {'1.0' '1.25' '1.75'};
%....some code to determine which outputFileName I should use
f=figure('visible','off');
%.....code to populate figure .....
fname = strcat('prefix', outputFileNames(index),'suffix');
print(f,'-dpsc2', '-append',fname)
Run Code Online (Sandbox Code Playgroud)
我一直收到这个错误:
Error using LocalCheckHandles (line 81)
Handle input argument contains non-handle value(s).
Error in print>LocalCreatePrintJob (line 366)
handles = checkArgsForHandleToPrint(0, varargin{:});
Error in print (line 160)
[pj, inputargs] = LocalCreatePrintJob(varargin{:});
Error in GenerateFieldPlots (line 57)
print(f,'-dpsc2', '-append',fname)
Run Code Online (Sandbox Code Playgroud)
当我检查fname的值时prefix1.0suffix(根据需要),当我检查index我得到的值时1.如果我替换fname = strcat('prefix', outputFileNames(index),'suffix');为fname = strcat('prefix', '1.0','suffix');程序运行正常并输出到预期的文件名.
最后一次尝试理解这个:
fname = strcat('prefix', outputFileNames(index),'suffix');
class(fname)
Run Code Online (Sandbox Code Playgroud)
产量char,和
fname = strcat('prefix', '1.0','suffix');
class(fname)
Run Code Online (Sandbox Code Playgroud)
也是收益率char.
我的问题:
为什么会这样?我的字符串数组不是真正的字符串数组吗?
我该如何解决?IE,我怎样才能使输出文件的名称动态化?
上面的问题是因为我有很多(> 5GB)数据需要转换成图并保存到文件中.最终,我需要在任何PC上打开的单个文档中的所有这些图(如... pdf!).为了实现这一点,我将所有数据作为单独的页面附加到postscript文件,然后将ps转换为pdf.不幸的是ps不是很节省空间,所以我最终得到一个巨大的 .ps文件.以上是我试图将一个巨大的 .ps拆分成几个较小的,我可以依次转换为pdf(然后组合成一个单独的pdf).这种方法非常复杂,但我一直无法找到更好的方法.你有建议更好地完成我的任务吗?
如果我遗漏了可能有用的任何细节,请告诉我.我是Matlab的新手,这是我关于Matlab的第一篇SO帖子!
考虑以下:
>> x = strcat('aaa',{'bbb'},'ccc')
x =
'aaabbbccc'
>> class(x)
ans =
cell
Run Code Online (Sandbox Code Playgroud)
我想你打算写:
fname = strcat('prefix', outputFileNames{index}, 'suffix');
Run Code Online (Sandbox Code Playgroud)
或者干脆:
fname = ['prefix', outputFileNames{index}, 'suffix'];
Run Code Online (Sandbox Code Playgroud)
请注意使用大括号而不是括号.