exist(obj.struct.var) always returns 0 regardless if the var exists or not.
Answer:
If you're not sure if the obj variable is a struct or has a field named struct, you can call isfield twice.
y = isfield(obj, 'struct') && isfield(obj.struct, 'var');
The first isfield call will return false if obj is not a struct or is a struct that does not have a field named struct. Only if the first isfield call returns true will the short-circuit && operator cause the second isfield call to be evaluated. In fact, that documentation page includes an example (Change Structure Field Value) that is somewhat related to this question.
obj = 42; % Not a struct y1 = isfield(obj, 'struct') && isfield(obj.struct, 'var') % false obj = struct('abc', 'def'); % struct but without the correct field y2 = isfield(obj, 'struct') && isfield(obj.struct, 'var') % false obj = struct('struct', struct('var', 'std')); y3 = isfield(obj, 'struct') && isfield(obj.struct, 'var') % true
for other assignment help please visit this site:
SEE COMPLETE ANSWER CLICK THE LINK
https://matlabhelpers.com/questions/how-to-exist-obj-struct-var-.php
The layout is intuitive, making it effortless for visitors to explore different categories and discover captivating content. Whether seeking the latest fashion trends, travel guides, tech reviews, or inspirational stories, HeraldDiary guarantees an enjoyable and seamless browsing experience. heralddiary
ReplyDeleteThese magazines consistently cover different topics, including politics, lifestyle, technology, entertainment, and so on. Their unique appeal lies in their ability to present news stories according to multiple perspectives, including diverse voices that could receive little exposure in mainstream media. mediosindependientes
ReplyDelete