Clear Filters
Clear Filters

Display header along with data in excel using GUI

2 views (last 30 days)
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?

Accepted Answer

Image Analyst
Image Analyst on 27 Jun 2022
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

More Answers (1)

Voss
Voss on 26 Jun 2022
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

Categories

Find more on MATLAB Report Generator in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!