how to save a UITable in Excell along with Rows & Column Names (Appdesigner, R2020a)

i have a data in in a variable 'A', i want to save it in excell file with rows and column names as shown in fighure below.
i tried
A = app.d;
filter = {'*.xlsx'};
[file,path] = uiputfile(filter);
filename = fullfile(path,file);
xlswrite(filename,A);
but this only save table not row names(a,b,c,d,e) and colomn names(Data,Average). kindly guide.

 Accepted Answer

Use writetable to solve your problem, there's a Name-Value pair that corresponds to your need. Here's the example: https://www.mathworks.com/help/matlab/ref/writetable.html#btydetm-1

5 Comments

Hello Mario.. i was out of station so accept my apalojize for late responding... i was confused that which command will exactly work for me.. i also used tried a little also on writetable but once again after ur confirmation that writetable is the correct choice i tried again. what i wrote
A = app.d;
Angle = {'1';'2';'3';'4'};
T1 = table(A,'RowNames',Angle);
writetable(T1,'test.xlsx',"WriteRowNames",true);
type 'test.xlsx'
now rownames are saving but i m unable to find same command like "ColumnNames"... is saving Variable 'A1'and 'A2' in column names.... i tried different ways to give it column names but it gives me different types of errors. like i tried
writetable(T1,Firstcolumn, secondcolumn,'test.xlsx',"WriteRowNames",true);
Second kindly also guide that where should i put "UIPutfile" so that it may popup to ask user to save file, current its saving by default names test in root folder.
I don't feel like opening the file because we went through similar process already.
What is A or app.d? Suppose you have a component called UITable.
writetable(app.UITable.Data, 'test.xlsx'); % notice the Data property
If you fill UITable Data property with your table T1, then you should get desired output.
However, I certainly don't want to ask what is this below. This means that you have not read documentation on the function, or you didn't do it in the proper way. Once again, don't try without reading the documentation, it'll save you huge amount of time.
writetable(T1,Firstcolumn, secondcolumn,'test.xlsx',"WriteRowNames",true);
You can put uiputfile in a callback of the button which user clicks when wants to save the button. Current directory will be opened in UI, unless you specify defname as a Name-Value argument.
yes 'app.d' containcs the UITtable data. Ok Mario i will again review the relavent Documentation for the function and Hopefully with indepth reading it will get resolved... wil update on this. Thanks
Dear Mario More than Thanks for ur Valuable suupport... all was helpfull but ur sentence that i will not get desired output unless i fill UITable.Data properly... and i focused on that while keeping in mind the directions of documentation... and finally i succedded... both with writing row and columns Names along with UIputfile..
i also want to share one of my mistake due to which it take much long time to achieve desire goal.. actually i was taking average of first column and displaying it in first row of second column... but when we assign row and column names then number of rows for each column should be same... so i changed my data and it works... due to this technical mistake which matlab was promting again and again i was not able to get my output even with proper code and syntax of Writetable.. Dear Mario once Again Thanks and i really appreciate that you Guide in such a way that encourage people for poolish them for troubleshooting...
sharing my working code file for those who will get help from this forum in future.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!