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!