Initialize App Designer data using external (Excel) file

2 ビュー (過去 30 日間)
Richard
Richard 2021 年 7 月 19 日
回答済み: Sivani Pentapati 2021 年 8 月 9 日
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.

回答 (1 件)

Sivani Pentapati
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

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by