Issues with passing uitable handle to a function
1 次查看(过去 30 天)
显示 更早的评论
Hello, I have 2 uitables that I want positioning using subplot notation hence:
ax1=subplot(2,2,1);
cnames={'x','ESF'};
% Create the uitable
t1 = uitable(f1,'Data',ESF',...
'ColumnName',cnames,...
'ColumnWidth',{50});
ax1,plot(3); pos = get(ax1,'position'); delete(ax1)
set(t1,'units','normalized'); set(t1,'position',pos)
ax2=subplot(2,2,2);
cnames={'x','offset'};
% Create the uitable
t2 = uitable(f1,'Data',offsets,...
'ColumnName',cnames,...
'ColumnWidth',{50});
ax2,plot(3); pos = get(ax2,'position'); delete(ax2)
set(t2,'units','normalized'); set(t2,'position',pos)
I also add a popup menu
popup = uicontrol('Style', 'popup',...
'String', {'ESF','Offsets'},...
'Value',1,...
'Position', [10 0 80 30],...
'Callback', @(src,evt) getAscii( src, evt,handles ));
Now depending on what the user selects, I want to copy the selected uitable contents to clipboard:
function getAscii(source,event,handles)
%cla(ax);
val = source.Value;
%indx = source.String;
switch val
case 1
disp('ESF')
d=get(t1,'data')
case 2
disp('Offsets')
d=get(t2,'data')
otherwise
disp('None')
end
%Copy to clipboard
size_d = size(d);
str = '';
for i = 1:size_d(1)
for j = 1:size_d(2)
if j == size_d(2)
str = sprintf('%s%f',str,d(i,j));
else
str = sprintf('%s%f\t',str,d(i,j));
end
end
str = sprintf('%s\n',str);
end
clipboard ('copy',str);
However, i'm not sure how to pass in the handles of ALL the uitable
5 个评论
Geoff Hayes
2018-4-3
Jason - it looks like you have programmatically created your GUI, so why not nest your function and callbacks in the main function so that they have access to the variables (in this case the handles) declared in the main function? See Nested Functions for more details.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!