Issues with passing uitable handle to a function
1 view (last 30 days)
Show older comments
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 Comments
Geoff Hayes
on 3 Apr 2018
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.
Answers (0)
See Also
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!