I wanna create a txt file and assign data from matlab variables into this file. The point is I wanna create txt file without opening any file like in the case of "save as" in world or excel. I also want that user can choose directory and file name.
Mostrar comentarios más antiguos
for example,
p = rand(5, 3)
startingFolder = 'C:\Program Files\MATLAB'
if ~exist(startingFolder, 'dir')
startingFolder = pwd
end
defaultFileName = fullfile(startingFolder, '*.txt*')
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a file')
if baseFileName == 0
return
end
fullFileName = fullfile(folder, baseFileName)
save(fullFileName, 'p', 'q', '-ASCII')
in here, I want that users don't have to need to open any file before saving data into this file , like in the "save as". So users would choose path and file name in the same dialog box once, then file would be saved directly without creating a blank txt file before.
Respuestas (1)
Iain
el 28 de Mayo de 2013
0 votos
Change uigetfile to uiputfile.
6 comentarios
sermet
el 28 de Mayo de 2013
Iain
el 28 de Mayo de 2013
Is the selected filename C:\Users\Hp\Desktop\xxx.txt* ? The * will cause issues.
sermet
el 28 de Mayo de 2013
Iain
el 28 de Mayo de 2013
A quick hack would be:
fullFileName(fullFileName == '*') = [];
I think you have an extraneous * in your default file extension, if you remove that, it ought to work.
sermet
el 28 de Mayo de 2013
Iain
el 28 de Mayo de 2013
I'm not sure you can using "save".
I'm not sure what you're really aiming for, but "dlmwrite", "csvwrite", and "xlswrite" are probably better suited to outputting nicely formatted text.
Categorías
Más información sobre Text Files en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!