How can I save a string as a filename and only include specific variables

2 views (last 30 days)
Hi, I'm trying to generate a .dat file, with a filename specified by the user, only including one variable from the file, an array titled A. I've managed to either save the .dat with the user-specified filename, or to save the .dat with a given filename and only including the array, but not the two at the same time.
To get a variable filename, I followed the advice here: http://www.mathworks.co.uk/matlabcentral/answers/42823 and typed
name = 'Enter filename: ';
file = input(name,'s');
save (file);
That generates a file with the name input (e.g. myfile.dat), but the contents are garbled.
To get a .dat file with the contents of A, I typed
save -ascii MatrixA.dat A;
That gives a .dat containing the values of A as required, but doesn't let the user change the filename. I've tried combining the two segments in various ways, but haven't managed to find any that work yet. I'd really appreciate any guidance!

Accepted Answer

Sean de Wolski
Sean de Wolski on 3 Dec 2013
save(file,'-ascii','A')
Call save with the variables inside of () rather than with spaces where they represent strins rather than values.

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!