Display header along with data in excel using GUI
조회 수: 2 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
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
댓글 수: 0
추가 답변 (1개)
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!