Unrecognized function or variable 'findobj'.
6 views (last 30 days)
Show older comments
I am developing an App in MATLAB. I created a button and callback during runtime. Inside the callback I am trying to find an object in the panel with tag.
findobj(event.Source.Parent.Children,'-regexp','Tag','XDropDown')
I get the following error.
Unrecognized function or variable 'findobj'.
2 Comments
Geoff Hayes
on 19 Jul 2023
@Saikrishna - do you need to provide the event.Source.Parent.Children? Looking at findobj('-regexp',prop,expr) that first input parameter doesn't seem to be needed and so may be the source of the error.
Answers (1)
Benjamin Kraus
on 19 Jul 2023
findobj is a built-in function and as such should "just work". The only thing I can think is that perhaps you accidentally shadowed the function temporarily and then deleted the shadow copy.
Can you try executing the command "rehash toolboxcache" to see if that resolves the issue.
If that doesn't work:
- Has findobj ever work for this particular MATLAB installation?
- Are any other graphics commands working? For example findall or figure or axes?
You may need to try reinstalling MATLAB or contacting Technical Support for assistance with this issue.
2 Comments
Walter Roberson
on 20 Jul 2023
It works in other Callback functions but i can't get it work in this callback.
If the problem were that the object you needed could not be found, then the three most common causes of that would be 1) that the object had been deleted; or 2) that the handle of the object was hidden; or 3) that the object had not been constructed yet.
If the problem were that it was telling "no such function findobj for type" something then you could potentially be passing in an object of a class that does not define findobj.
If findobj worked in one callback but gave you "no such function findobj" without saying "no such function or variable" then you would have the obscure difficulty of having created a function that assigned to a variable named findobj but also having tried to call the function findobj before the variable was assigned. These days when you assign to a variable inside a function, you cannot also call the function that has the same name. For example,
function test(s)
ts = sum(s);
sum = 0;
for K = 1 : numel(s); sum = sum + double(s(K)); end
if sum ~= ts; fprintf('sum was %g but total is %g\n', ts, sum);
end
This code would fail with an error about no such function sum because the assignment to a variable named sum inside the function would have hinted to MATLAB that inside the function the name sum is only going to refer to a variable.
But you say you are getting an error about "no such function or variable", and the only way for to happen for findobj is if you had changed the MATLAB path so that it no longer includes findobj .
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!