필터 지우기
필터 지우기

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

조회 수: 47 (최근 30일)
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?

채택된 답변

Iain
Iain 2013년 5월 22일
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
sermet
sermet 2013년 5월 22일
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 2013년 5월 22일
uiputfile is what you want to use to get the filename (and path). - The help documentation will tell you all about it.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2013년 5월 22일
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');

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by