Initialize App Designer data using external (Excel) file

조회 수: 7 (최근 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 CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by