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: Juan Pablo Carbajal
Subject: Re: Using a string variable as a filename #2
Date: Tue, 8 Nov 2011 21:37:23 +0100

On Tue, Nov 8, 2011 at 8:34 PM, Al Slavin <address@hidden> wrote:
> 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
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://mailman.cae.wisc.edu/listinfo/help-octave
>

For any situation, when you need to use a variable as the name of the
file to save, you have to use the save() function, passing the
arguments.
So your example works if
save("-ascii", filename3, "A")


-- 
M. Sc. Juan Pablo Carbajal
-----
PhD Student
University of Zürich
http://ailab.ifi.uzh.ch/carbajal/


reply via email to

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