Why am I getting an error 'Could not compare values in DATA and VALUESET using the equality operator' when adding drop down list to app designer table?
2 ビュー (過去 30 日間)
古いコメントを表示
Hello all! My first post here, so go easy on me. I am trying to set a column in an app designer table to a categorical drop down list following this example here: https://www.mathworks.com/matlabcentral/answers/452199-how-can-i-have-dropdown-in-every-cell-of-a-table-in-app-designer#answer_367306
It seems my code is equivalent to what was done in that example, but I am getting this error:
"Error using categorical (line 596)
Could not compare values in DATA and VALUESET using the equality operator.
Caused by:
Undefined function 'eq' for input arguments of type 'cell'."
I am getting this error at the t.Lead = categorical(......) line of code, but this code seems identical to the solution in the link above. I also run the code in the link in the command window (outside the app) and everything works fine. Any help is greatly appreciated because I am obviously missing something.
The table BOM_Small is a 3 column table with a number in first column, string (Part Number) in each cell of the second column, and string description in third column.
Here is my code:
% Button pushed function: ImportPartListfromFileButton
function ImportPartListfromFileButtonPushed(app, event)
BOM_File = uigetfile; %grab file from browser
opts_BOM = detectImportOptions(BOM_File); %detect the import option from the file. It will likely contain string and number variables
S_BOMFile = size(readtable(BOM_File,opts_BOM)); %Detects the number of size of the imported file [Rows, columns]
if S_BOMFile(2) ~= 3 && S_BOMFile(2) ~= 12 %checks to make sure the uploaded BOM is an acceptable size
ER = errordlg('Subsystem Bill of Materials is Not an Acceptable Size','BOM Upload Error')
elseif S_BOMFile(2) == 3
BOM_Small = readtable(BOM_File,opts_BOM); %read in the three column spreadsheet
Lead = cell(S_BOMFile(1),1); %create empty cell array for lead types
LeadOrientation = cell(S_BOMFile(1),1); %create empty cell array for lead orientation
for i = 1:length(LeadOrientation)
LeadOrientation{i,1} = {'<Undefined>'}; %Set all values in Lead orientation to undefined
Lead{i,1} = {'Undefined'}; %Set all values in lead type to undefined
end
GroundPadArea = zeros(S_BOMFile(1),1); %create a column vector of zeros for ground pad area
InterconnectPitch = zeros(S_BOMFile(1),1); %create a column vector of zeros for component lead pitch
SolderPadArea = zeros(S_BOMFile(1),1); %create a column vector of zeros for single solder pad area
CharLength = zeros(S_BOMFile(1),1); %create a column vector of zeros for characteristic length
t = table(BOM_Small{:,1},BOM_Small{:,2},BOM_Small{:,3},Lead,LeadOrientation,GroundPadArea,InterconnectPitch,SolderPadArea,CharLength); %create table with all necessary vectors
t.Lead = categorical(t.Lead,{'Undefined','Leaded','Leadless'}); %set lead type to a categorical with drop down list
t.LeadOrientation = categorical(t.LeadOrientation,{'<Undefined>','Full','Perimeter'});
app.UITableBOMVar.Data = t; %set data to UITAble variable
app.UITableBOMVar.ColumnEditable = [true true true true true true true true true];
elseif S_BOMFile(2) == 12
app.UITableBOMVar.Data = readtable(BOM_File,opts_BOM);
end
end
0 件のコメント
回答 (1 件)
Sameer
2024 年 4 月 26 日
Hi Craig
From my understanding you want to modify a column in an App Designer table to display a categorical dropdown list. The process involves reading a table from a file, dynamically creating additional columns based on the file's content, and then converting specific columns to categorical types with predefined categories.
The encountered error typically arises from an issue with how the categorical function attempts to process cell arrays. Specifically, the error message indicates a problem with using the equality operator to compare values in the data and the specified value set because the data is comprised of cell arrays containing cell arrays, rather than strings or character arrays directly.
When initializing variables such as “Lead” and “LeadOrientation”, ensuring they are cell arrays of strings rather than cell arrays of cell arrays can help avoid this issue. This can be achieved by adjusting the manner in which these variables are populated:
for i = 1:length(LeadOrientation)
LeadOrientation{i,1} = '<Undefined>'; % Ensuring this is a string
Lead{i,1} = 'Undefined'; % Also ensuring this is a string
end
In the code snippet above, removing the curly braces {} and assigning strings directly to the cell array positions ensures that “Lead” and “LeadOrientation” are cell arrays of strings. This adjustment is critical for the proper functioning of the categorical conversion:
t.Lead = categorical(t.Lead, {'Undefined', 'Leaded', 'Leadless'});
t.LeadOrientation = categorical(t.LeadOrientation, {'<Undefined>', 'Full', 'Perimeter'});
With these changes, the categorical function should be able to process the cell arrays as intended, converting them into categorical arrays without encountering the previously mentioned error.
I hope this helps!
Sameer
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Develop Apps Using App Designer についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!