How can i save a .xls file in a specific folder?
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Tristan Yang
el 2 de En. de 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 comentarios
Ver también
Categorías
Más información sobre File Operations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!