Access different property from set method in class
18 ビュー (過去 30 日間)
古いコメントを表示
Hello all,
I have a class that has a user-controlled property to turn on/off the use of gpuArrays. I want to access this property in a "set" method for a different property. That way, I can immediately store the new property in GPU memory upon calling the set method. However, I see the warning: "A set method for a non-Dependent property should not access another property ('useGpu')". Is there a smarter way to have access to the useGpu property? The use of a global variable seems sloppy to me.
My set method looks as follows:
function obj = set.smaps(obj,val)
val = single(val);
if obj.useGpu
obj.smaps = gpuArray(val);
end
end
0 件のコメント
採用された回答
Steven Lord
2019 年 4 月 11 日
As long as the get method for the useGpu property doesn't try to set the smaps property (leading to an infinite loop) and as long as your class doesn't satisfy both the criteria in the first section of this documentation page I think you're probably okay.
This is a warning alerting you to the possibility that you may be doing something problematic. If you understand what you're doing you can suppress the message for the line of code where the warning is reported, see the "Adjust Code Analyzer Message Indicators and Messages" section on that documentation page.
It is not an error alerting you to the certainty that what you're doing won't work (trying to name a variable 2x or something similar.) The only way to suppress errors and have your code work is to correct the syntactically invalid code.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Graphics Object Properties についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!