Save matrix as a spreadsheet image

1 visualización (últimos 30 días)
Varun Kumar
Varun Kumar el 13 de Jul. de 2022
Comentada: Adam Danz el 13 de Jul. de 2022
I am trying to programatically save a matrix as a .jpg or .png file. The output should be a jpg that looks like a spreadsheet, similar to an excel document. For example, if the matrix was:
1 2 3
4 5 6
7 8 9
The output of the program should look something like this (screenshot from excel) in a jpg or png file:
What function should I use to make this happen?
Thank you!

Respuesta aceptada

Adam Danz
Adam Danz el 13 de Jul. de 2022
Editada: Adam Danz el 13 de Jul. de 2022
Storing numeric data in images makes it difficult to work with those data later on but I remember a use-case for this back when I wanted to quickly snap-shot small data sets for visual reference (still not sure it was the best approach).
Nevertheless, if your matrix fits on a single page, you could put the data in a uitable and then extract the figure using exportapp. Note that precision may be lost since there is a finite number of decimal places that will appear on the table. See uitable documentation to learn how to apply column and row labels.
x = rand(10,5)*100;
fig = uifigure(); % must be uifigure
uit = uitable(fig,'Units','Normalize','Position',[0 0 1 1],'Data', x)
After the figure and uitable are rendered, you can export the figure as an image using exportapp.
% drawnow % only needed if calling exportapp immediately after uitable.
% pause(.5) % only needed if calling exportapp immediately after uitable.
exportapp(fig, 'mytable.png')
  7 comentarios
Varun Kumar
Varun Kumar el 13 de Jul. de 2022
Sorry, another issue just arose. What do I do if my matrix does not fit on one page? Can I resize it?
Thanks!
Adam Danz
Adam Danz el 13 de Jul. de 2022
What is your matrix size?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Specifying Target for Graphics Output en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by