Effacer les filtres
Effacer les filtres

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

8 vues (au cours des 30 derniers jours)
Francesco Dall'Orto
Francesco Dall'Orto le 29 Déc 2017
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

Réponses (1)

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

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by