Generalizing Function Calls with Property Dependence in App Designer
조회 수: 3 (최근 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에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!