"Saravanan Mani" wrote in message <ocfrl3$3ba$1@newscl01ah.mathworks.com>...
> "Mark Chalmers" wrote in message <ocfpa4$rf3$1@newscl01ah.mathworks.com>...
> > I know this is an old issue but I had the same problem (r2016b) and spent over a day to find the solution, which I couldn't find in the forums. So here it is for the rest of you struggling with this frustration...
> >
> > The problem occurs if the string variable you pass into the print function was built up of 'str' and 'char' data types it will not work and gives the error:
> >
> > "Error using checkArgsForHandleToPrint
> > Handle input argument contains nonhandle values."
> >
> > The solution is to convert all input variables to 'char' data types. (see example below)
> >
> > % TestFolder = string('C:\MATLAB_Export'); % doesn't work
> > TestFolder = char('C:\MATLAB_Export'); % does work
> > FileID = 1;
> > FileName = sprintf('FileNo_%g',FileID);
> > ExportFile = strcat(TestFolder,'\',FileName);
> >
> > x = 1:10;
> > y = x.^2;
> > f = figure;
> > plot(x,y);
> >
> > print(f,ExportFile,'-dpng');
>
>
> Dear Mark,
>
> Can you try following code.
>
> % TestFolder = string('C:\MATLAB_Export'); % doesn't work
> TestFolder = 'C:\MATLAB_Export'; % does work
> mkdir(TestFolder);
> FileID = 1;
> FileName = sprintf('FileNo_%g',FileID);
> % ExportFile = strcat(TestFolder,'\',FileName);
> x = 1:10;
> y = x.^2;
> f = figure;
> plot(x,y);
> print(f,[TestFolder '\' FileName],'-dpng');
>
> Thanks & Regards,
> Saravanan
Saravanan,
Your code is fine, but I'm not sure what you are trying to prove with it though.
TestFolder = 'C:\MATLAB_Export'; results in a 'char' data type, not a 'str'.
I wrote "char( 'C:\MATLAB_Export')" just to highlight the point.
The problem was never because the folder didn't exist, I had a check in there for that already.
I hope this clarifies the problem.
Best regards,
Mark.
> "Mark Chalmers" wrote in message <ocfpa4$rf3$1@newscl01ah.mathworks.com>...
> > I know this is an old issue but I had the same problem (r2016b) and spent over a day to find the solution, which I couldn't find in the forums. So here it is for the rest of you struggling with this frustration...
> >
> > The problem occurs if the string variable you pass into the print function was built up of 'str' and 'char' data types it will not work and gives the error:
> >
> > "Error using checkArgsForHandleToPrint
> > Handle input argument contains nonhandle values."
> >
> > The solution is to convert all input variables to 'char' data types. (see example below)
> >
> > % TestFolder = string('C:\MATLAB_Export'); % doesn't work
> > TestFolder = char('C:\MATLAB_Export'); % does work
> > FileID = 1;
> > FileName = sprintf('FileNo_%g',FileID);
> > ExportFile = strcat(TestFolder,'\',FileName);
> >
> > x = 1:10;
> > y = x.^2;
> > f = figure;
> > plot(x,y);
> >
> > print(f,ExportFile,'-dpng');
>
>
> Dear Mark,
>
> Can you try following code.
>
> % TestFolder = string('C:\MATLAB_Export'); % doesn't work
> TestFolder = 'C:\MATLAB_Export'; % does work
> mkdir(TestFolder);
> FileID = 1;
> FileName = sprintf('FileNo_%g',FileID);
> % ExportFile = strcat(TestFolder,'\',FileName);
> x = 1:10;
> y = x.^2;
> f = figure;
> plot(x,y);
> print(f,[TestFolder '\' FileName],'-dpng');
>
> Thanks & Regards,
> Saravanan
Saravanan,
Your code is fine, but I'm not sure what you are trying to prove with it though.
TestFolder = 'C:\MATLAB_Export'; results in a 'char' data type, not a 'str'.
I wrote "char( 'C:\MATLAB_Export')" just to highlight the point.
The problem was never because the folder didn't exist, I had a check in there for that already.
I hope this clarifies the problem.
Best regards,
Mark.