Borrar filtros
Borrar filtros

How can i save a .xls file in a specific folder?

8 visualizaciones (últimos 30 días)
Francesco Dall'Orto
Francesco Dall'Orto el 29 de Dic. de 2017
Respondida: Tristan Yang el 2 de En. de 2018
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

Respuestas (1)

Tristan Yang
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

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by