"Unrecognized method, property, or field 'Type' for class 'matlab.ui.control.WebComponent'."
20 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Dave Watson
il 13 Apr 2024
Modificato: Fangjun Jiang
il 11 Set 2025 alle 14:13
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 Commenti
Risposta accettata
Fangjun Jiang
il 14 Apr 2024
Modificato: Fangjun Jiang
il 14 Apr 2024
I think app.tabFiles.Children is an array of handles. Try tf = strcmp(get(app.tabFiles.Children,'Type'), 'uistatebutton')
2 Commenti
Fangjun Jiang
il 16 Apr 2024
Modificato: Fangjun Jiang
il 11 Set 2025 alle 14:13
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
Più risposte (1)
Viren
il 11 Set 2025 alle 11:28
Modificato: Viren
il 11 Set 2025 alle 11:30
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 Commenti
Vedere anche
Categorie
Scopri di più su Create Custom UI Components in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!