How can I implement this code within a function?

3 views (last 30 days)
I am trying to run this code within a function rather than in the main m-file.
When I run this inside of the main m-file I dont have any problems, but when I try to run it within a function I get the error:
Undefined function or variable 't'.
Error while evaluating uitable CellEditCallback
Note: this error only occurs when editing the table values in the uitable
LN = 5;
%dat=uitbl(LN);
%selection types available to user
selector_1 = {'T300'; 'AS'; 'P100 ';'Boron-epoxy'; 'Scothply';'Eglass'; 'Kevlar '};
selector_2 = {'LM'; 'IMLS'; 'IMHS '; 'HM '; 'Polymide'; 'PMR '};
cformat = {{selector_1{:}},{selector_2{:}}...
'numeric','numeric','numeric'};
%predefines the column 1&2 selections and row 3-5 as 0
dat = repmat({'T300','LM','0','0','6'},LN,1);
%column titles
cnames = {'<html><center /><font size=-2>Fiber Mat<br /> </html>',...
'<html><center /><font size=-2>Matrix Mat<br /> </font></html>',...
'<html><center /><font size=-2>Angle (deg)<br /> </font></html>',...
'<html><center /><font size=-2>Thickness (mm)<br /> </font></html>',...
'<html><center /><font size=-2>Vf<br /> </font></html>'};
%row titles (numbers 1 - LN)
rnames = (1:LN);
%this supresses errors if the user doesn't edit the table
ans=dat;
%uitable prompt
f = figure('Position',[20 30 510 130+LN*17]);
t = uitable('parent',f,...
'data',dat,...
'ColumnName',cnames,...
'ColumnFormat',cformat,...
'columneditable',true(1,5),...
'RowName',rnames,...
'CellEditCallback','get(t,''Data'';)',...
'RearrangeableColumns', 'on',...
'Position', [50 50 413 35+LN*17]);
%waits for user to close figure window before continuation of code
%uiwait(gcf)
waitfor(gcf);
%saves ans to data
dat = ans;
  1 Comment
Stephen23
Stephen23 on 5 Mar 2015
Could you please upload the complete and exact file that this function is in, preferably both the script and functions version that you are trying. You can use the paperclip button to attach files to your question (and don't forget to click "Attach File").

Sign in to comment.

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!