Output of get() somehow not usable for set() for uicontrols

조회 수: 6 (최근 30일)
Smattering_Applause
Smattering_Applause 2021년 12월 15일
답변: Smattering_Applause 2021년 12월 15일
I have a gui where there's a number of buttons on it that I want to disable during a loading process. Once I get a list of the children of the figure that have the 'Enable' property I run the following to get the current status of the buttons
statuses = get(objList,'Enable');
I then change all the 'Enable' values using set() and a single status (not array), this works fine
set(objList,'Enable','off');
I then let other code run, and finally reset the 'Enable' value to what they were, but this throws the error
set(objList,'Enable',statuses);
Below is the text of the error. I have played around with using set and get and I think I have found the interaction problem. Individually, each item in objList can take 'on', 'off' without problem. But since statuses is a cell array of the values, they can't handle it.
Error using matlab.ui.control.WebComponent/set
Error setting property 'Enable' of class 'UIControl':
Invalid enum value. Use one of these values: 'on' | 'off' | 'inactive'.
Example:
This runs file.
set(objList(39),'Enable','off');
But this fails for the same reason as above.
set(objList(39),'Enable',{'off'});
From my understanding of the set() function however, it should work. I have m graphics objects in objList, n (1) property values in 'Enable', and mxn values in the array statuses. What am I doing wrong?
  • set(H,NameArray,ValueArray) specifies multiple property values using the cell arrays NameArray and ValueArray. To set n property values on each of m graphics objects, specify ValueArray as an m-by-n cell array, where m = length(H) and n is equal to the number of property names contained in NameArray.

채택된 답변

Smattering_Applause
Smattering_Applause 2021년 12월 15일
While writing this question and confirming results, I believe I discovered the critical difference in what I was trying to run and what was expected. Namely, for multiple changes at once to work, NameArray has to be forced as a cell array, even for a 1x1 size. Similarly, if NameArray is a 1x1 cell, then ValueArray has to be a cell array as well or else it'll error
Works:
set(objList(1),'Enable','on') % since both name and value are non-cells
set(objList(1),{'Enable'},{'on'}) % since both name an value are cells and appropriate size
set(objList,{'Enable'},statuses) % since Name is a cell (n) and objList is array (m) and statuses is mxn size
Doesn't work:
set(objList(1),'Enable',{'on'}) % since name is not a cell and value is a cell
set(objList(1),{'Enable'},'on') % similar to above, but name is cell but value is not
set(objList,'Enable',statuses) % since name is not a cell, but statuses is.
I think my confusion stemmed from the dearth of detail on the input arguments (see how for interp1 each portion is explained whereas set just has examples and tips)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by