How to: write .xls into a dynamic folder name ?

조회 수: 1 (최근 30일)
John Doe
John Doe 2020년 12월 2일
댓글: John Doe 2020년 12월 2일
Hello everyone,
It may be a silly question for you all folks, but i'm kick in a teeth on that one...
First the code and then what i want to do.
Prompt={'Nom', 'Surname', 'Birth_date (mm dd aaaa)','Evaluation_date (mm dd aaaa)'};
Dlgtitle=' patient data';
Def={'Duarte','Mickaels','01 01 2000','16 02 2018'};
Answer=inputdlg(Prompt,Dlgtitle,1,Def);
Patient_info={Answer{1},Answer{2},Answer{3}};
Eval_date={'Evaluation',Answer{4}};
Muscle={'Fl_Pr','Ex_Su','Bic','Tri'};
Task=[1;2;3;4;5;6];
Task1={'Task'};
mkdir ([Answer{1},' ',Answer{2},' ',num2str(Answer{3})]) % create folder with data from the prompt Patient_info
xlswrite(???????????????.xls,Task,'Fpic','A5'));
xlswrite((???????????????..xls,Patient_info,'Fpic','A2'));
xlswrite((???????????????.,Eval_date,'Fpic','A3'));
xlswrite((???????????????.,Muscle,'Fpic','B4'));
xlswrite((???????????????.,Task1,'Fpic','A4'));
I'm trying to write an .xls into the folder i just created for each of my patients from the data i put in the prompt.
If someone can help...
Thanks you all !

채택된 답변

Walter Roberson
Walter Roberson 2020년 12월 2일
편집: Walter Roberson 2020년 12월 2일
folder = [Answer{1},' ',Answer{2},' ',num2str(Answer{3})];
if ~exist(folder, 'dir'); mkdir(folder); end
filename = 'patient_data.xlsx';
fullname = fullfile(folder, filename);
xlwrite(fullname, Task, 'Fpic', 'A5');
xlswrite(fullname, Patient_info, 'Fpic', 'A2');
and so on.
Are you sure you want spaces in the folder name? That is legal, but it does tend to make programming more difficult. For example,
system(['dir ', fullname])
would fail because of the spaces in the file name, and you would need
system(['dir "', fullname, '"'])
  댓글 수: 1
John Doe
John Doe 2020년 12월 2일
Thanks Walter, mixed with the answer of Jegan, it works flawlessly ! You're life saver !
About the folder name it's not an obligation, i have let the space because it's a small programm but i see your point :) thanks for the extra info ;)

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

추가 답변 (1개)

Ananthi Jegan
Ananthi Jegan 2020년 12월 2일
Hi John
You can create the excel files dynamically from the inputs received in Prompt as follows:
xlswrite(fullfile(XLFilePath,XLFilename),Array,Sheet,Range) where XLFilename should be the name of file including the extension '.xlsx' or '.xls'
An example to use from above lines of code:
xlswrite(fullfile(XLFilePath,XLFilename),Muscle,'Fpic','B4')
I hope this answers your query.
  댓글 수: 1
John Doe
John Doe 2020년 12월 2일
Thanks Jegan, mixed with the answer of Walter, it works flawlessly ! You're life saver too :) !

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

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by