private variables in a matlab GUI
7 views (last 30 days)
Show older comments
Hello,
I'm brand new to Matlab, but am knowledable enough to be dangerous as a coder in general. I'm just looking for a best practice here. I've created a GUI to run tests on a benchtop electronics assembly. In the GUI I would like to change settings, pass them to a function and store the results in an array of structures that contain all my test data.
This in the variable I would like to be my array of structures
properties (Access = private)
results;
end
This is what is executed when the user hits the "runTest" button.
% Button pushed function: RunTestButton
function run(app, event)
for x = 1:app.NumberofTestsEditField.Value
app.results(x) = runTest(app.paramX.Value,...
app.paramY.Value,...
app.paramZ.Value,...
)
pause(app.TimeBetweenTestsEditField.Value);
end
end
The error I get is it cannot covert a structure to a double. As stated, I am looking for best practices. runTest does indeed return a structure with some strings, doubles etc. I am presuming it thinks the results variable I defined as a private variable is of type double (I didn't tell it that). Do I just need need to init it as a variable that has the same structure that is being return for runTest()? I don't know how large it is going to be. Appreciate your patience as I am brand new at this :)
Thanks!
Bob
0 Comments
Answers (1)
Steven Lord
on 17 May 2023
Before you enter the loop, by the way you've defined it the results property of the app is a double array. You can't assign a struct into an element of a double array; MATLAB doesn't know how to perform that conversion.
s = struct('x', 1, 'y', 2, 'z', 3);
x = 1:10;
x(2) = s % error
You could initialize app.results to be a struct either in the definition of the property or as the first line of that method using the struct function.
0 Comments
See Also
Categories
Find more on Write Unit Tests in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!