I have a script that is printing images to a file. I want the name of the file that I print to to be dynamic - ie I want the output file name to depend on some parameters. Kind of like this:
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)
I keep getting this error:
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)
When I check the value of fname I get prefix1.0suffix (as desired) and when I check the value of index I get 1. If I replace fname = strcat('prefix', outputFileNames(index),'suffix'); with fname = strcat('prefix', '1.0','suffix'); The program runs fine and outputs to the expected file name.
Last attempt at making sense of this:
fname = strcat('prefix', outputFileNames(index),'suffix');
class(fname)
yields char, and
fname = strcat('prefix', '1.0','suffix');
class(fname)
also yields char.
My questions:
Why is this happening? Is my array of strings not really an array of strings?
How do I fix this? IE, how can I make the output file's name dynamic?
Above issues come about because I have a lot (>5GB) of data that I need to convert into plots and save to files. Ultimately I need all these plots in a single document that can be opened on any PC (like... pdf!). To accomplish this I'm appending all my figures as individual pages to a postscript file and then converting the ps to pdf. Unfortunately ps's are not very space-efficient, so I'm ending up with a giant .ps file. Above is my attempt to break up a single giant .ps into several smaller ones which I can convert to pdf's in turn (and then combine into a single pdf). Such an approach is very convoluted, but I have been unable to find a better way. Do you have a suggestion for a better way to accomplish my task?
Please let me know if I've left out any details that might be helpful. I'm new to Matlab and this is my first SO post regarding Matlab!
Consider the following:
>> x = strcat('aaa',{'bbb'},'ccc')
x =
'aaabbbccc'
>> class(x)
ans =
cell
I think you meant to write:
fname = strcat('prefix', outputFileNames{index}, 'suffix');
or simply:
fname = ['prefix', outputFileNames{index}, 'suffix'];
Note the use of braces instead of parentheses.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With