Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
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!

Akzeptierte Antwort

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

Weitere Antworten (0)

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by