Initialize App Designer data using external (Excel) file
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Sivani Pentapati
2021-8-9
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!