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

2 次查看(过去 30 天)
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!

采纳的回答

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by