Dynamically name a TextArea
1 回表示 (過去 30 日間)
古いコメントを表示
My GUI have 81 TextAreas. The names are indexed, e.g. A1TextArea and A2TextArea.
App.A1TextArea.Value = 1 changes A1TextArea to 1
What is the code to change the Nth TextArea programatically? N is a variable
App.A+'n'+TextArea.Value = 1
1 件のコメント
Stephen23
2025 年 4 月 2 日
Rather than using pseudo-indices in text, why not use actual indices? Then your task is achieved using basic indexing.
採用された回答
Walter Roberson
2025 年 4 月 2 日
編集済み: Walter Roberson
2025 年 4 月 2 日
for n = 1 : 81
App.("A" + n + "TextArea").Value = 1
end
That said, it is better to create an array of text areas instead of naming them each individually. With an array of text boxes you could do
set(App.TextAreas, 'Value', 1)
to set the Value property of all of the TextAreas at the same time.
その他の回答 (1 件)
Steven Lord
2025 年 4 月 2 日
While you can access property names dynamically as stated in the "Reference Properties Using Variables" section of this documentation page:
R = RandStream.getGlobalStream;
R.Type % Accessing a property using a name known when the code is written
name = 'Type';
R.(name) % Accessing a property using a name that could vary at run-time
In this case I'd consider using one property that contains an array of handles. With that you can index into an element of the array to access a particular handle.
f = figure(Color = 'r');
textObjectHandles = gobjects(2);
for k = 1:4
textObjectHandles(k) = uicontrol(Style='text', Units='normalized', ...
Position=[0.1 0.2*k 0.5 0.1], String = string(k));
end
textObjectHandles
textbox3 = textObjectHandles(1, 2)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
