Initialize App Designer data using external (Excel) file
2 views (last 30 days)
Show older comments
I have a large number of data fields that I want to initialize in a for loop reading the name and value from an Excel worksheet. Reading the worksheet is no problem. Reading the worksheet produces an array of object names, and a corresponding value array. I don't want to use a long list of assignments which I believe would eliminate insuring that I was loading the data in corresponding objects. What I'm looking for is a way to do the following:
for i=1:<number of objects>
app.<name(i)> = value(i);
end
Is there some way to reference an existing component by constructing the reference using a string or cell?
I'm leaving this question open, but did some additional experimentation and found that for a component app.data I can reference its value either by app.data.Value or app.('data').Value. This should let me easily pre-load these components by reading name and value from an external source.
0 Comments
Answers (1)
Sivani Pentapati
on 9 Aug 2021
Based on my understanding, you want to initialize the data fields by reading name and value entries from an Excel sheet. You can use readtable to load the data into a variable. The values in the table can then be updated following the standards of MATLAB indexing, where "app.UITable.Data" works as a matrix.
Below code populates the data in b to the first row of a table with four columns without using a for loop
b = [1,2,3,4];
app.UITable.Data(1,1:4) = b(:);
For more information you can also look into the documentation of uitable
0 Comments
See Also
Categories
Find more on Develop Apps Using App Designer 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!