Generalizing Function Calls with Property Dependence in App Designer
2 ビュー (過去 30 日間)
古いコメントを表示
I have code that is formatted like below in App Designer. Properties I1, I2, and I3 are all callable from an instrument with their own method. So far I've just been repeating the same code in each button push callback, but I want to write a general function instead so I don't repeat code. The example below is a simple one for this purpose, but you could imagine how convoluted it could get for several methods. I understand why the code below doesn't work (it's calling a string, not the property). I am unclear as to how to generalize a format of a property and call it in the function. Help is appreciated.
Version 2020b. An upgrade is possible, if that assists with the solution.
%this is the start of App Designer
properties (Access = private)
I1
I2
I3
end
methods (Access = private)
function change_current(app, unit_number)
prop_name = join(["I", unit], '')
app.prop_name.current(40) %the code errors here as it should, since it's calling a string and not the property...how to do?
end
end
0 件のコメント
採用された回答
chicken vector
2023 年 4 月 19 日
編集済み: chicken vector
2023 年 4 月 19 日
Use:
app.(prop_name).current
to use strings as class properties (or structure fields).
その他の回答 (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!