"isfield" for hidden field in optimoptions

조회 수: 3 (최근 30일)
Sargondjani
Sargondjani 2025년 2월 11일
편집: Matt J 2025년 2월 11일
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?

채택된 답변

Walter Roberson
Walter Roberson 2025년 2월 11일
편집: Walter Roberson 2025년 2월 11일
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
Walter Roberson 2025년 2월 11일
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
Stephen23 2025년 2월 11일
Such situations are also easily handled by the user: isstruct(S) && isfield(S,..)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt J
Matt J 2025년 2월 11일
편집: Matt J 2025년 2월 11일
One way:
options = optimoptions(@fsolve,'JacobPattern',speye(5));
isNonDefault = ~isequal(options.JacobPattern, optimoptions(@fsolve).JacobPattern )
isNonDefault = logical
1

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by