필터 지우기
필터 지우기

Display header along with data in excel using GUI

조회 수: 2 (최근 30일)
Sush Gautam
Sush Gautam 2022년 6월 26일
답변: Image Analyst 2022년 6월 27일
A = [12.7 5.02 -98 63.9 0 -.2 56];
B = [2 3 4 5 6 7 8];
c= transpose([A;B]);
[file,path] = uiputfile('*.xlsx');
filename = fullfile(path,file);
xlswrite(filename,c);
Using above code, I can only save data in excel but not their corresponding headers A and B. How can I do it in GUI?

채택된 답변

Image Analyst
Image Analyst 2022년 6월 27일
Try to make a table and then write it out with writetable
% Create sample data.
A = [12.7 5.02 -98 63.9 0 -.2 56];
B = [2 3 4 5 6 7 8];
% Make a table
t = table(A(:), B(:), 'VariableNames', {'A', 'B'})
% Create an output filename.
[baseFileName, folder] = uiputfile('*.xlsx');
fullFileName = fullfile(folder, baseFileName);
fprintf('Saving Excel file : "%s".\n', fullFileName)
% Write the workbook to disk.
writetable(t, fullFileName);
% Open it up to verify its contents.
if ispc
winopen(fullFileName);
end

추가 답변 (1개)

Voss
Voss 2022년 6월 26일
A = [12.7 5.02 -98 63.9 0 -.2 56];
B = [2 3 4 5 6 7 8];
% c= transpose([A;B]);
c = num2cell(transpose([A;B])); % make c a cell array
headers = {'A' 'B'}; % use whatever headers you want
[file,path] = uiputfile('*.xlsx');
filename = fullfile(path,file);
% xlswrite(filename,c);
xlswrite(filename,[headers; c]); % include the headers when writing

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by