"isfield" for hidden field in optimoptions
21 ビュー (過去 30 日間)
古いコメントを表示
hi,
with Matlab 2019 it seems that:
options = optimoptions(@fsolve,'JacobPattern',speye(5))
isfield(options,'JacobPattern')
will return 0. But options.JacobPattern will return the speye(5).
I guess this is due to the hidden nature of JacobPattern. I want the code to check if the field is specified or not.
How do I do that?
0 件のコメント
回答 (2 件)
Walter Roberson
2025 年 2 月 11 日 20:06
編集済み: Walter Roberson
2025 年 2 月 11 日 20:09
optimoptions returns on object of class optim.options.Fsolve not a struct.
You need to use
isprop(options,'JacobPattern')
However, more likely is that you want
isprop(options,'JacobPattern') && ~strcmp(options.JacobPattern), 'sparse(ones(Jrows,Jcols))')
3 件のコメント
Walter Roberson
2025 年 2 月 11 日 20:31
I dunno. It is documented though
If S is not a structure array, then isfield returns 0.
I guess it makes it marginally easier to handle the situation where a function returns either a structure array or else []
Stephen23
2025 年 2 月 11 日 20:49
Such situations are also easily handled by the user: isstruct(S) && isfield(S,..)
参考
カテゴリ
Help Center および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!