user3129463
user3129463

Reputation: 35

Saving a text file

I want to save a matrix as .text with a variable filename. Currently I'm saving my file using the function dlmwrite(name,matrix); This is only working with a pre-set filename. Is there a way to make the name of the file variable?

A window that pops up that ask for a filename to write to just as 'Uigetfile' does with opening a file would be ideal. Does anyone know if Matlab got a function just like that for writing text files?

Upvotes: 1

Views: 160

Answers (1)

Luis Mendo
Luis Mendo

Reputation: 112759

You can use uiputfile to graphically get the file name. For example:

[filename, pathname, filterindex] = uiputfile('', 'Select file');

Then use dlmwrite to save a variable, say data, to that file:

dlmwrite(fullfile(pathname, filename), data)

Upvotes: 2

Related Questions