Problem with creating EnumType and store it into DataDictionary
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello,
My goal is to define an enum type and put it into my Data Dictionary.
In order :
- Extract data from spreadsheet containing : Name of an enum type, element names and elements values ( Done )
- Use this data to define an EnumType (Done)
- Store this enum type into my data dictionnary
First,I used the tutorial on this webpage about the Simulink.data.dictionary.EnumTypeDefinition class that defines an enum class called myColors
I am on the help pages of my version Matlab 2018b
myColors = Simulink.data.dictionary.EnumTypeDefinition;
appendEnumeral(myColors,'Blue',3,'');
appendEnumeral(myColors,'White',4,'');
appendEnumeral(myColors,'Red',5,'');
removeEnumeral(myColors,1);
myColors.Description = 'These are my favorite colors.';
myColors.DefaultValue = 'Blue';
myColors.HeaderFile = 'colorsType.h';
myDictionaryObj = Simulink.data.dictionary.open('dic.sldd');
importFromBaseWorkspace(myDictionaryObj,'varList',{'myColors'});
myDictionaryObj.saveChanges
Simulink.data.dictionary.closeAll
It works, I have no problem with that, i just have to define a script and paste the result.
BUT
I want to create a function that takes the necessary informations that I extracted from Excel and create an enum type accordingly ( and this function will be used recursively to declare all enum type whose name i extracted).
so I juste put this code into a function with another enum type:
function [OK] = test_enum_fct(dic)
% Function that creates an EnumTypeDefinition and put it into the
% DataDictionary <dic>
%------------------------Input------------------------
% <dic>(String) = name of the DD WITH extension .sldd
%------------------------Output-----------------------
% <OK> (String) PROTO !!! = test output
Othercolors = Simulink.data.dictionary.EnumTypeDefinition;
appendEnumeral(Othercolors,'Purple',3,'');
appendEnumeral(Othercolors,'Orange',4,'');
appendEnumeral(Othercolors,'Black',5,'');
removeEnumeral(Othercolors,1);
Othercolors.Description = 'These are my favorite colors.';
Othercolors.DefaultValue = 'Black';
Othercolors.HeaderFile = 'OthercolorsType.h';
myDictionaryObj = Simulink.data.dictionary.open(dic);
importFromBaseWorkspace(myDictionaryObj,'varList',{'Othercolors'});
myDictionaryObj.saveChanges
Simulink.data.dictionary.closeAll
OK = 'OK';
end
If i execute it into the command Window I get error (line 19 is the line importFromBaseWorkspace(myDictionaryObj,'varList',{'Othercolors'}); )
Error using test_enum_fct (line 19)
An error occurred evaluating the entry list:
Caused by:
Error using test_enum_fct (line 19)
entry names list element 'Othercolors' was not found
And if i create a script that execute this function with proper 'dic.sldd' as input i get the warning dialog
Error using test_enum_fct (line 19)
Error Message:
An error occurred evaluating the entry list:
The myDictionnaryObj Dictionary is open and the handle is in my workspace, as well as the Othercolors EnumTypeDefinition. I put breakpoint before the error and typing Othercolors in the Command Window returns the good result :
K>> Othercolors
Othercolors =
Simulink.data.dictionary.EnumTypeDefinition
Purple
Orange
Black
Question : Is this a bug ? or intended ? How can i correct this ? Is there a way to circumvent this knowing that i have to respect the input (recursive, multiple Excel Input, multiple Enum classes, must be done programmatically) ?
Other information :
When i try to access my enumTypeDefinition in the Workspace to see what elements there is, I have an error message :
Editing of enumerated type 'Othercolors' is only supported in a data dictionary
I still didnt put it into my Data Dictionnary and just want to check. Is this normal behaviour ?
Sincerely
Jan
2 Commenti
Guillaume
il 20 Dic 2019
Is this required to be in Simulink (which I know nothing about), what's the purpose of this?
When posting error messages give us the full text. Matlab typically includes the line content, not just the number, so we don't have to gues which line is line 19.
If the line
importFromBaseWorkspace(myDictionaryObj,'varList',{'Othercolors'});
is meant to import the Othercolors variable that you've created earlier in the function, then from the name of the function, I would assume this is never going to work. The Othercolors variable is in the function workspace which is completely separate from the base workspace.
If the purpose is to create key-value store (aka a dictionary, map or hashtable) then the whole thing seems overly complicated but maybe that's the way simulink works. In pure matlab, you wouldn't be playing around with workspaces.
Risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
