Filter löschen
Filter löschen

While using save command, I wanna choose directory which files can be saved into it.

47 Ansichten (letzte 30 Tage)
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?

Akzeptierte Antwort

Iain
Iain am 22 Mai 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 Kommentare
sermet
sermet am 22 Mai 2013
for example, my data is string=[1;2,3] which is string into listbox in GUI (after processing). I wanna save this data by clicking push button, I wanna open dialog box which enables users to write file name and choose path for saving the file with .txt format.
Iain
Iain am 22 Mai 2013
uiputfile is what you want to use to get the filename (and path). - The help documentation will tell you all about it.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Image Analyst
Image Analyst am 22 Mai 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');

Kategorien

Mehr zu File Operations finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by