using same variable for two separate button to run and show the output
2 次查看(过去 30 天)
显示 更早的评论
i try to use two buttons in appdesigner one for table and one for plot both using the same varaibles which was loaded from excel file how ever when i try to run it and press plot button i get error as shown in another picture even thou i used the properties function
and here is my code so far
properties (Access = private)
t % table to share
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
end
% Button pushed function: readdataButton
function readdataButtonPushed(app, event)
app.t = readtable (['Specimen_RawData_1.csv']);
var=app.t(10:end,1:2) ; %define your variables according to columns
var.Var1(1)=99;
d= (table2array(app.t(10:end,"Var1"))).*11
nr = array2table(d) ;% cell array
app.UITable.Data = [var(:,1:1:2) nr];
app.t.Properties.VariableNames{1} = 'time (s)';
app.t.Properties.VariableNames{2} = 'Extention';
app.UITable.ColumnName = app.t.Properties.VariableNames;
x = table2array(app.t(10:end,"time (s)"));
y = table2array(app.t(10:end,"Extention"));
plot(app.UIAxes,x,y);
end
% Button pushed function: plotButton
function plotButtonPushed(app, event)
x = table2array(t(10:end,"time (s)"));
y = table2array(t(10:end,"Extention"));
plot(app.UIAxes,x,y);
0 个评论
回答(1 个)
Steven Lord
2022-5-15
There's no variable named t in the workspace of the plotButtonPushed function.
If you had used app.t in that code, that would refer to the t property of the app object.
By the way, you might want to spell your second variable name as "Extension" not "Extention". I would consider defining a Hidden private property with the variable names so you could refer to those properties in each method and not risk accidentally spelling the name differently in the methods.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!