using same variable for two separate button to run and show the output

2 views (last 30 days)
Shaghayegh Ghandali
Shaghayegh Ghandali on 15 May 2022
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
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
% 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
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"));
% Button pushed function: plotButton
function plotButtonPushed(app, event)
x = table2array(t(10:end,"time (s)"));
y = table2array(t(10:end,"Extention"));

Answers (1)

Steven Lord
Steven Lord on 15 May 2022
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.




Community Treasure Hunt

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

Start Hunting!