フィルターのクリア

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 Center および File ExchangeSpreadsheets についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by