How can I put images in a table using gui?
26 次查看(过去 30 天)
显示 更早的评论
I need to create a table in matlab/gui where I have to put images in the first column of the table. Is that possible? I searched a lot for a code to help me but I couldn't find any.
0 个评论
采纳的回答
Adam Danz
2023-4-7
编辑:Adam Danz
2023-4-7
Here's a demo that embeds images in cells of a uitable but as @Walter Roberson mentioned, the image size will be small, and the aspect ratio may change since all icons are the same size.
uistyle is used to create icons from the images and addStyle is used to place the images in the uitable cells.
% 1. Create a demo table of images
images = ["circle.jpg" "clock.jpg" "catherine.jpg" "hexagon.jpg", "laure.jpg", "pearswtx.jpg" "star.jpg" "triangle.jpg"];
T = table('Size',[numel(images),5], ...
'VariableTypes',["string" "string" "double" "double" "double"], ...
'VariableNames',["Image" "Format" "BitDepth" "Width" "Height"]);
T.Image = images(:);
for i = 1:numel(images)
info = imfinfo(T.Image(i));
T.Format(i) = info.Format;
T.BitDepth(i) = info.BitDepth;
T.Width(i) = info.Width;
T.Height(i) = info.Height;
end
% 2. Create the uitable and embed images in column 1.
fig = uifigure;
uit = uitable(fig,"Data",T, ...
'Units','normalized', ...
'Position',[.05 .05 .9 .9], ...
'FontSize', 16);
for i = 1:height(T)
imgStyle = uistyle("Icon",T.Image(i));
addStyle(uit, imgStyle, 'cell', [i,1])
end
15 个评论
Adam Danz
2023-4-16
exportapp does not have an append option. You can combine PDF files into one file using other software.
更多回答(2 个)
Walter Roberson
2023-4-6
If you use traditional figures with traditional uitable() objects, then Yes, it is possible.
What you do in such cases is use a cell array of character vectors, and set each one to be HTML, such as
D{2,5} = '<HTMTL><IMG source="http://SOMEURL">'
However.... it is difficult to adjust the size of the cells. You can adjust column width, but column height is going to be automatically determined to be equivalent to one line in the text font (the scanner is just going to see text, not understanding that it is going to activate something.) So you can effectively only get fairly small images, on the order of 10-ish pixels high.
If you are using uifigure() with newer uitable() then there might be additional possibilities.
If you are using uifigure() then consider the possibility of using uihtml() objects https://www.mathworks.com/help/matlab/ref/uihtml.html beside the uitable(); see also https://www.mathworks.com/help/matlab/creating_guis/create-an-html-file-that-sets-data-or-responds-to-data-changes-from-matlab.html
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Printing and Saving 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!