How can i save a .xls file in a specific folder?
12 views (last 30 days)
Show older comments
Hi! I'm trying to save a .xls file in a specific folder. I will show you my code:
mkdir (['TEST\' char(nameFolder)]);
fullPath=fullfile(['TEST\' char(nameFolder)], "*nameOfVariable*");
xlswrite(fullPath, "*variable*")
For example if i have a variable named "Hello" that contain the array [1,2,3] I want to create a folder in TEST\nameFolder that contain a file.xls named Hello.xls in which i have the array [1,2,3]
Thank you very much
0 Comments
Answers (1)
Tristan Yang
on 2 Jan 2018
If the name of the variable is needed as the filename, it is necessary to store that information as a 'char'. For example:
nameOfVariable = 'Hello';
Hello = [1, 2, 3];
Then you can write the variable to a spreadsheet with:
mkdir (['TEST\' char(nameFolder)]);
fullPath=fullfile(['TEST\' char(nameFolder)], [nameOfVariable '.xls']);
xlswrite(fullPath, Hello);
If you would like to dynamically matching the variable name with the array/matrix value, please consider using one cell array to store all the variable names and another cell array to store the corresponding array/matrix. For example:
names = {'hello1', 'hello2', 'hello3'};
values = {[1,2,3], [4,5,6], [7,8,9]};
mkdir (['TEST\' char(nameFolder)]);
for i = 1:length(names)
fullPath=fullfile(['TEST\' char(nameFolder)], [names{i} '.xls']);
xlswrite(fullPath, values{i});
end
0 Comments
See Also
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!