While using save command, I wanna choose directory which files can be saved into it.
47 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
for example;
p = rand(1, 10)
q = ones(10)
save('pqfile.txt', 'p', 'q', '-ASCII') % in here I cannot choose the directory which pqfile will save into it. I wanna save this file another directory, can I choose a different path?
0 Commenti
Risposta accettata
Iain
il 22 Mag 2013
You need to provide save with the path. eg.
save('C:\here.txt','p','p','-ASCII');
Or you can save to where you're working then use copyfile to put it where you want.
Or you can change directory to where you want the data, save it as you have just now, then change directory back to where you started (loop up "cd" in help)
4 Commenti
Iain
il 22 Mag 2013
uiputfile is what you want to use to get the filename (and path). - The help documentation will tell you all about it.
Più risposte (1)
Image Analyst
il 22 Mag 2013
A fairly robust way if you're going to hard code in the folder:
folder = 'C:\Users\sermet\Documents'; % Or wherever
if exist(folder, 'dir') == 0
% Make folder if it does not exist.
mkdir(folder);
end
% Create full filename with the fullfile() function:
fullFileName = fullfile(folder, 'pqfile.txt');
save(fullFileName, 'p', 'q', '-ASCII');
Or, if you're going to have the user specify a file, try it this way:
% Have user browse for a file, from a specified "starting folder."
% For convenience in browsing, set a starting folder from which to browse.
startingFolder = 'C:\Program Files\MATLAB';
if ~exist(startingFolder, 'dir')
% If that folder doesn't exist, just start in the current folder.
startingFolder = pwd;
end
% Get the name of the file that the user wants to use.
defaultFileName = fullfile(startingFolder, '*.*');
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)
save(fullFileName, 'p', 'q', '-ASCII');
Vedere anche
Categorie
Scopri di più su File Operations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!