Create a Table able to be exported in PNG following Latex Type style.

조회 수: 58 (최근 30일)
Jorge Ignacio Cisneros Saldana
Jorge Ignacio Cisneros Saldana 2022년 7월 25일
답변: Siraj 2023년 9월 13일
Hello:
I am trying to create a table, that can be exported in the directory in .PNG or any figure type.
The best would be to export it as Latex looking .png.
I tried multiple ways and I cannot succed.
The only conversion I found to create a Latex table is the following. Here you can create a .Tex file.
I would appreciate your help

답변 (1개)

Siraj
Siraj 2023년 9월 13일
Hi! It is my understanding that you want to export a table as a PNG file.
To export a table as a PNG file, you can utilize MATLAB's "uitable" function. This function creates a table UI component within the current figure and returns the “table” UI component object. The key aspect is to align the table properly so that it occupies the entire figure and appears visually appealing. This can be achieved by adjusting the position of the uitable and figure.
Once the table is positioned correctly, you can convert the figure to an image using the "getframe" and "frame2im" functions. After obtaining the image data, you can save it as a PNG file using the "imwrite" function. To gain a better understanding, refer to the example code provided below.
% creating a table.
LastName = {'Sanchez';'Johnson';'Li';'Diaz';'Brown'};
Age = [38;43;38;40;49];
Smoker = logical([1;0;1;0;1]);
Height = [71;69;64;67;64];
Weight = [176;163;131;133;119];
T = table(LastName,Age,Smoker,Height,Weight);
%create a new figure.
fig = uifigure;
%create a uitable
uit = uitable(fig, "Data",T);
% adjusting the table to fit the entire figure for cleanliness.
uit.Position(3) = fig.Position(3) - 80;
uit.Position(4) = fig.Position(4) - 80;
% Capture the table window as an image
frame = getframe(fig); % Get the current figure window
imageData = frame2im(frame); % Convert the frame to an image
% Save the image as a PNG file
imwrite(imageData, 'table.png');
I have attached "table.png" for your reference
For a more comprehensive understanding of the "uitable" function in MATLAB and its properties, I recommend referring to the following link:
This resource will provide you with detailed information on how to effectively position a table and utilize its various properties.
To learn more about “getframe”, “frame2im” and “imwrite” refer to the following links.
Hope this helps.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by