help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Using a string variable as a filename #2


From: Al Slavin
Subject: RE: Using a string variable as a filename #2
Date: Tue, 08 Nov 2011 14:34:44 -0500

William,

Thanks, your reply was very useful and seems to have solved my saving of a 
graphics file.

I now have a related question, that does not seem to handled in the same way.  
If I want to use  a string variable as the file name for saving a variable, 
your example made me try the following, which did not work, as commented below. 
 Suggestions?

Al Slavin
__________________________________________
clear
a=2
filename1="somefilename"
filename2=sprintf('filename1%d.dat', a)   %Prints this correctly as 
somefilename12.dat
outpath=pwd
filename3=fullfile(filename2)  

A=[1 2;3 4]
save -ascii filename3 A;   %Saves as "filename3", not as "somefilename12.dat".  
Parentheses around "filename3" does not help.
____________________________________________________________




>>> William Krekeler <address@hidden> 07/11/2011 10:54 am >>>
To print a figure to a specific filename. You can replace gcf with a figure 
handle. Also I default to saving to png so you would need to change the flag 
and filename end.

figure, plot( 1:10 );
outputPath = pwd;
counter_in_loop = 1;    % just added to put something in the sprintf to show 
that filenames can be built from variable content
print( gcf, '-dpng', fullfile( outputPath, ...
 sprintf('some_file_name_%d.png', counter_in_loop) ) );

William Krekeler



reply via email to

[Prev in Thread] Current Thread [Next in Thread]