Saving a text file

2020-04-30 02:13发布

问题:

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?

回答1:

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)


标签: matlab file save