"Unrecognized method, property, or field 'Type' for class 'matlab.ui.control.WebComponent'."
    19 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Dave Watson
 el 13 de Abr. de 2024
  
    
    
    
    
    Editada: Fangjun Jiang
      
      
 el 11 de Sept. de 2025
            In App Designer (MATLAB R2024a, Windows 10 Pro, 64-bit) I have a tab (app.tabFiles) that has a few ui components on it. When I query the Type property on all of them at once, I get the following error:
tf = strcmp({app.tabFiles.Children.Type}, 'uistatebutton') ;  % This works fine with 7 other tabs, panels, etc
"Unrecognized method, property, or field 'Type' for class 'matlab.ui.control.WebComponent'."
However, if I query the Type of the components individually, each happily returns its Type. Huh?
I should mention, there are 13 components visible on the tab and 13 listed in the Component Browser. However, the tab has 14 Children - the extra child is the label (set to empty string) on a uieditfield component - but all respond as expected to the individual Type request.
Any idea what would cause that exception to be thrown? And how to avoid it?
0 comentarios
Respuesta aceptada
  Fangjun Jiang
      
      
 el 14 de Abr. de 2024
        
      Editada: Fangjun Jiang
      
      
 el 14 de Abr. de 2024
  
      I think app.tabFiles.Children is an array of handles. Try tf = strcmp(get(app.tabFiles.Children,'Type'), 'uistatebutton')
2 comentarios
  Fangjun Jiang
      
      
 el 16 de Abr. de 2024
				
      Editada: Fangjun Jiang
      
      
 el 11 de Sept. de 2025
  
			Here is another example that the "dot property name" method does not work on arry of objects. 
close all;plot(1:3);
obj=findobj(0)
obj(1).Type
get(obj,'Type')
obj.Type
Más respuestas (1)
  Viren
 el 11 de Sept. de 2025
        
      Editada: Viren
 el 11 de Sept. de 2025
  
      Thanks @Fangjun Jiang! Your solution to use v = get(h,propertyNames) and set(h,NameArray,ValueArray) functions worked perfectly for me. I had a slightly different setup:
I was working with a GUI tab that contains a grid layout named GridLayout_LabelCheckboxAndSpinner, which holds 34 UI components - a mix of checkboxes, labels, and spinners. When I ran:
app.GridLayout_LabelCheckboxAndSpinner.Children
I got a 34x1 graphics array, confirming that all components were correctly placed under the grid layout and each has an 'Enable' property.
However, when I tried to retrieve the 'Enable' property value of single component using:
singleComponentEnableProp = app.GridLayout_LabelCheckboxAndSpinner.Children(1).Enable
                ans =                 
                      OnOffSwitchState enumeration
                          off
This technique worked for single component one after another, or you can either make a for loop to retrive all component's 'Enable'property.
However, when I tried to retrieve the 'Enable' property for all components at once using:
allComponentsEnablePropArray = app.GridLayout_LabelCheckboxAndSpinner.Children(:).Enable
I encountered the following error:
Unrecognized method, property, or field 'Enable' for class 'matlab.ui.control.internal.model.ComponentModel'. 
This happened because I was trying to access all Children the 'Enable' property directly from the array, which doesn't work for heterogeneous UI components. These components are all part of the same graphics array, but they belong to different classes (e.g., matlab.ui.control.Label, matlab.ui.control.CheckBox, etc.).
Instead, I used the get function:
allComponentsEnablePropArray = get(app.GridLayout_LabelCheckboxAndSpinner.Children, 'Enable')
This successfully returned a cell array of 'Enable' states.
To restore or apply these states back to the components, I used:
arrayfun(@(i) set(app.GridLayout_LabelCheckboxAndSpinner.Children(i), 'Enable', allComponentsEnablePropArray{i}), 1:numel(allComponentsEnablePropArray))
This worked perfectly, assigning each 'Enable' value to its corresponding component.
0 comentarios
Ver también
Categorías
				Más información sobre Create Custom UI Components en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



