Asi*_*rif 4 treeview matlab user-interface image jtree
我在Matlab工作.当用户鼠标单击树列表中的文件名时,我想逐个显示给定面板中的图像.谁能帮帮我吗?

树的代码:
src = strcat(pwd,'\Result\');
[mtree, container] = uitree('v0', 'Root',src,???
'Position',[10 10 290 370],'Parent', imageListPanel2); % Parent is ignored
set(container, 'Parent', imageListPanel2); % fix the uitree Parent
Run Code Online (Sandbox Code Playgroud)
在面板中显示图像的功能:
function refreshDisplay(varargin)
imgDisplayed = imshow(tmp,'parent',workingAx);
end %refreshDisplay
Run Code Online (Sandbox Code Playgroud)
我只需要知道如何从我的树中调用函数refreshDisplay().再次记住,我想从树元素(文件)调用函数而不是从节点(子目录)调用.
问候.
以下是一个快速但完整的示例.代码已注释且易于遵循:
function MyImageViewer
% prepare GUI
hFig = figure('Menubar','none', 'Name','Image Viewer');
hPan(1) = uipanel('Parent',hFig, 'Position',[0 0 0.3 1]);
hPan(2) = uipanel('Parent',hFig, 'Position',[0.3 0 0.7 1]);
ax = axes('Parent',hPan(2), 'Units','normalized', 'Position',[0 0 1 1]);
axis(ax, 'off', 'image')
[jtree,htree] = uitree('v0', 'Parent',hFig, ...
'Root','C:\Users\Amro\Pictures\', 'SelectionChangeFcn',@changeFcn);
set(htree, 'Parent',hPan(1), 'Units','normalized', 'Position',[0 0 1 1]);
jtree.expand(jtree.getRoot); % expand root node
% list of supported image extensions
fmt = imformats;
imgExt = lower([fmt.ext]);
function changeFcn(~,~)
% get selected node
nodes = jtree.getSelectedNodes;
if isempty(nodes), return; end
n = nodes(1);
% only consider a leaf node (skip folders)
if ~n.isLeaf, return; end
% get complete node path (absolute filename)
p = arrayfun(@(nd) char(nd.getName), n.getPath, 'Uniform',false);
p = strjoin(p(:).', filesep);
% check for supported image types, and show image
[~,~,ext] = fileparts(p);
if any(strcmpi(ext(2:end),imgExt))
imshow(p, 'Parent',ax)
end
end
end
Run Code Online (Sandbox Code Playgroud)
