필터 지우기
필터 지우기

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

조회 수: 8 (최근 30일)
Francesco Dall'Orto
Francesco Dall'Orto 2017년 12월 29일
답변: Tristan Yang 2018년 1월 2일
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

답변 (1개)

Tristan Yang
Tristan Yang 2018년 1월 2일
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

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by