how to create a new folder mkdir, but naming that folder as input before running the code
이전 댓글 표시
Hi all,
I am not sure if the title is clear. Basically, every time I will run the code, I want a new folder to save my m.files and figures.
That new folder, should be called as the project name that I chose, for example "set_one". This should be easily changed at the beginning of the code, and not to be changed manually from all the related commands every time I change the data sets.
an example
fname = 'set_one'; % this should be the proyect title
Image data = [12.7 5.02 -98 63.9 0 -.2 56];
mkdir('C:\Users\Desktop\matlab results\',fname);
filename=('C:\Users\Desktop\matlab results\fname\Image_Data');
save(filename,'Image_Data')
..And it does not work. mkdir does create a new folder as set_one, but is not able to recognize the new folder as set_one. Therefore, error message says that the folder does not exist.
What I am trying to do is that on the filename line, where it says fname, should be rewritten dynamically by the name I give to fname.
Thanks in advance,
Regards
채택된 답변
추가 답변 (1개)
Peyman Obeidy
2018년 4월 24일
not quite sure what you want to do, but try this
clear
clc
path =[pwd '\'];
stru =dir( fullfile(path, '*.vsi') );
fileNames = { stru.name };
outputPath = [path 'NewImage2\'];
mkdir(outputPath);
for iFile = 1: numel(fileNames)
fileName=fileNames{iFile}; % read the file name here
numofName=str2double(fileName(7:end-4)); % cut out all but the number
newFileNum=numofName;
newName = fullfile([outputPath 'Image_' , sprintf('%02d.vsi', newFileNum)] );
copyfile(fullfile(path, fileNames{iFile}), newName );
end
댓글 수: 3
ARP
2018년 4월 24일
Peyman Obeidy
2018년 4월 24일
do you want your code to ask you the name? something like;
prompt = {'Enter a name of the folader'};
title = 'Folder name';
definput = {'Set_one'};
opts.Interpreter = 'tex';
answer = inputdlg(prompt,title,[1 40],definput,opts);
ARP
2018년 4월 24일
카테고리
도움말 센터 및 File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!