using same variable for two separate button to run and show the output
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/999210/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/999215/image.png)
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 Kommentare
Antworten (1)
Steven Lord
am 15 Mai 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.
Siehe auch
Kategorien
Mehr zu Axis Labels finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!