Issues with passing uitable handle to a function

1 visualizzazione (ultimi 30 giorni)
Jason
Jason il 3 Apr 2018
Modificato: Jason il 3 Apr 2018
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 Commenti
Geoff Hayes
Geoff Hayes il 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.
Jason
Jason il 3 Apr 2018
Modificato: Jason il 3 Apr 2018
So I got the following working:
f1=figure
myhandles.table1 = t1;
% Save the structure
guidata(f1,myhandles)
and then in my functionI can access the selected table contents as:
d=get(myhandles.table1,'data')
thanks Rik. Also Geoff, I will look into your suggestion also, thanks

Accedi per commentare.

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by