How can I export the ANOVA results as a PNG?

Hi,
I am doing an ANOVA (similar to the one in the example page) and I was wondering if there is a way to export that information that you get as a png?
Since I have to publish the results of the anova it would be super if I could just generate a picutre.
Thank you for you help.

1 Comment

I am using the example from here: https://www.mathworks.com/help/stats/anovan.html
I just want the table which is shown in the field on the right.

Sign in to comment.

Answers (2)

Adam Danz
Adam Danz on 6 Sep 2020
Edited: Adam Danz on 30 Apr 2021
> How can I export the ANOVA results as a PNG?
If you're refering to the boxplot results, to save a figure as png, saveas(fig,filename,'png') where fig is the figure handle and filename is the name or, better yet, the full path (using fullfile) of the png output file. Get the figure handle using gcf.
If you're refering to the ANOVA table displayed in the figure, you woudn't want to insert that into a document as an image. It would be much better to save the table variable to a text file. Example:
[p, tbl, stats] = anova1(___);
writecell(tbl,'anovaresults.txt') % better to use full path
The txt file will be comma separated and will not maintain the column-aligned formatting. However, it will be easy to read back into Matlab using
tbl = readcell('anovaresults.txt');
Update If you're using Matlab R20201a or later, you can use formattedDisplayText to convert the table to a string that maintains its format which is demonstrated in this community highlight. The string can then be written to a text file using fprintf or another text writing function.
If the text file is going to be read back into Matlab, the first option is best. If the file is meant for human eyes, the formattedDisplayText option is best.
[p, tbl, stats] = anova1(___);
% Convert table to string
tblStr = formattedDisplayText(tbl);
% Write string to file
fid = fopen('anovaTable.txt', 'wt');
fileCleanup = onCleanup(@()fclose(fid));
formatSpec = '%s\n';
fprintf(fid, formatSpec, tblStr);
clear('fileCleanup')
Sample of results:

4 Comments

Thanks for getting back to me.
I would like to insert the results as an Image, simply because formating tables in latex is a huge pain in the ass. I really like the way that the table looks in matlab and it would be super if I could just export it like the graphs.
I hope that clears things up.
You can use the saveas function in my answer to save the figure containing the table. I would be surprised if journals accept it, though.
You can also check out export_fig() which gives you more options.
Thank you again for your answer.
I cant get the saveas to work. I keep getting this error:
Unrecognized function or variable 'fig'.
Adam Danz
Adam Danz on 6 Sep 2020
Edited: Adam Danz on 10 Sep 2020
From my answer, "where fig is the figure handle". If you don't have the figure handle, use gcf() assuming the figure is the current figure.

Sign in to comment.

Tags

Asked:

on 6 Sep 2020

Commented:

on 30 Apr 2021

Community Treasure Hunt

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

Start Hunting!