フィルターのクリア

Insert number in structure array

1 回表示 (過去 30 日間)
Chad
Chad 2023 年 6 月 22 日
編集済み: Stephen23 2023 年 6 月 23 日
Dear Forum,
I would like to do a loop and change the number in the following array.
app.Channel2EditField_1.Value = minVal_ch2
Here I want to change the value "1" after each loop. For example,
The next loop it will be
app.Channel2EditField_2.Value = minVal_ch2
Then
app.Channel2EditField_3.Value = minVal_ch2
Any help is appreaciated.
  1 件のコメント
Stephen23
Stephen23 2023 年 6 月 22 日
"Any help is appreaciated."
Don't force pseudo-indices into the fieldnames. Use read indices:

サインインしてコメントする。

採用された回答

Paul
Paul 2023 年 6 月 22 日
Hi Chad,
If possible, consider changing the structure of your data to arrays that can be indexed, instead of field names that contain a character that really seems to be an index.
But if you can't ... then use dynamic field names
minVal_ch2 = 5.3; % example
for ii = 1:3
app.("Channel2EditField_" + string(ii)).Value = minVal_ch2;
end
app
app = struct with fields:
Channel2EditField_1: [1×1 struct] Channel2EditField_2: [1×1 struct] Channel2EditField_3: [1×1 struct]
app.Channel2EditField_2
ans = struct with fields:
Value: 5.3000
  1 件のコメント
Chad
Chad 2023 年 6 月 22 日
編集済み: Stephen23 2023 年 6 月 23 日
Thank you. This works perfectly.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by