Unrecognized function or variable 'findobj'.

조회 수: 6 (최근 30일)
Saikrishna
Saikrishna 2023년 7월 19일
댓글: Walter Roberson 2023년 7월 20일
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
Geoff Hayes
Geoff Hayes 2023년 7월 19일
@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.
Saikrishna
Saikrishna 2023년 7월 19일
i tried with findobj('-regexp',prop,expr) it didn't work either.

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

답변 (1개)

Benjamin Kraus
Benjamin Kraus 2023년 7월 19일
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
Saikrishna
Saikrishna 2023년 7월 19일
편집: Saikrishna 2023년 7월 19일
It works in other Callback functions but i can't get it work in this callback.
It's a dropdownbutton and I created dropdownopening callback and valuechanged callback. It works in dropdown opening callback but not in Valuechanged.
app.leftPanelCopyObj(i).Children(iChildren).DropDownOpeningFcn = createCallbackFcn(app, @app.dropdown1, true);
app.leftPanelCopyObj(i).Children(iChildren).ValueChangedFcn = createCallbackFcn(app, @app.valuechangedfcn2, true);
Walter Roberson
Walter Roberson 2023년 7월 20일
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 .

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by