- In Code View, press the "+Property" button in the Insert section of the Editor Tab of the toolstrip.
- In the editor, rename "Property" to "t" (or another name you like)
- In your VerbindenButton and CAN0Button callbacks, change "t" to "app.t"
Two Buttons with same Variable in App Designer
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Fabian Merlin Hoffmann
am 17 Mai 2016
Bearbeitet: Melissa Williams
am 17 Mai 2016
Hi Guys,
I'm new to the App Designer and I have a (simple?) question:
I have two buttons. The first one opens a tcp/ip connection to a device. The callback function got the following code (just ignore the lamps):
% Button button pushed function
function VerbindenButton(app)
t = tcpip('192.168.2.3', 29536, 'NetworkRole', 'Client')
fopen(t);
app.Lamp.Enable = 'on';
app.Lamp2.Enable = 'off';
end
% Button2 button pushed function
function CAN0Button(app)
fwrite(t,'< open can0 >');
end
When I click the second button (after the first one) I get the error 'Undefined function or variable 't'.' So here is my question: How do I get the value/information of t into the second button function?
0 Kommentare
Akzeptierte Antwort
Melissa Williams
am 17 Mai 2016
Bearbeitet: Melissa Williams
am 17 Mai 2016
Hi Fabian, You can add an app property to pass data from one callback to another. To do this:
To learn more you can refer to this documentation: http://www.mathworks.com/help/matlab/creating_guis/share-data-across-callbacks-in-app-designer.html
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Develop Apps Using App Designer 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!