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

조회 수: 1 (최근 30일)
Shaghayegh Ghandali
Shaghayegh Ghandali 2022년 5월 15일
댓글: Shaghayegh Ghandali 2022년 5월 15일
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);

답변 (1개)

Steven Lord
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 CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by