Create a Table able to be exported in PNG following Latex Type style.
57 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!