フィルターのクリア

How to save app.UITable as image (.png for example)

23 ビュー (過去 30 日間)
Dominique
Dominique 2023 年 2 月 28 日
コメント済み: Dominique 2023 年 3 月 28 日
I have a GUI with App Designer to populate a UITable object.
A button press will populate the table. The output is for example as in screenshot below:
I need to save this output as .png
Is there a way to a achieve this?
Thanks.

採用された回答

DUY Nguyen
DUY Nguyen 2023 年 3 月 2 日
編集済み: DUY Nguyen 2023 年 3 月 2 日
Hi Dominique,
You can take a screenshot of the figure using the getframe function. Then, you can save the screenshot as a PNG file using the imwrite function. The below code worked!
You may modify the code and put it in the click_button_function. If you have the table on the UIaxes, you may need to copy the contents of the UIAxes object to the new figure: copyobj(axes, fig);
% Get the figure handle
fig = uifigure('Name', 'Table Figure');
t = uitable(fig, 'Data', magic(5));
% Take a screenshot of the figure
screenshot = getframe(fig);
% Save the screenshot as a PNG file
imwrite(screenshot.cdata, 'table.png', 'png');
  1 件のコメント
Dominique
Dominique 2023 年 3 月 28 日
Hi DUY Nguyen,
Thanks for your reply. I tired it. It was a good tip.
This is actually placing the uitable in a parent uifigure. Then saves the figure as .png.
The tough part is the fact that the figure size is not the same as the table size. The fig size is way too big.
I tried something like
fig.Position(3:4) = t.Position(3:4)
I had to set the fig.Position manually. It's a hard way, but it's ok for my application.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by