MATLAB Answers

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

18 views (last 30 days)
John Doe
John Doe on 2 Dec 2020
Commented: John Doe on 2 Dec 2020
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 !

  0 Comments

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 2 Dec 2020
Edited: Walter Roberson on 2 Dec 2020
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 Comment

John Doe
John Doe on 2 Dec 2020
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 ;)

Sign in to comment.

More Answers (1)

Ananthi Jegan
Ananthi Jegan on 2 Dec 2020
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 Comment

John Doe
John Doe on 2 Dec 2020
Thanks Jegan, mixed with the answer of Walter, it works flawlessly ! You're life saver too :) !

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by