how to convert structure variables into a simulink.parameter object
6 views (last 30 days)
Show older comments
Iam storing varaibles in targetStruct from excel sheet. For example targetStruct has variables B00200, B1115 under name field.
I want to convert those structure variables(B00200, B1115) into a simulink.parameter object in the targetStruct . is tis possible?
The below is the code .
T = readtable('VCU_UDS_DTC_Information_00_06_Backup.xlsx','Sheet','VCU_0.6');
dataStruct=table2struct(T);
targetStruct = struct([]);
for i=1:numel(dataStruct)
b=dataStruct(i).SAE_J2012_DTC;
c=dataStruct(i).SAE_J2012_FTB;
b=num2str(b);
c=num2str(c);
concat=strcat(b,c);
targetStruct(i).name=concat;
0 Comments
Answers (1)
R
on 26 Mar 2024
To convert the variables stored in the 'targetStruct' structure into a 'Simulink.Parameter' object, you can modify your code as follows:
T = readtable('VCU_UDS_DTC_Information_00_06_Backup.xlsx','Sheet','VCU_0.6');
dataStruct = table2struct(T);
targetStruct = struct([]);
for i = 1:numel(dataStruct)
b = num2str(dataStruct(i).SAE_J2012_DTC);
c = num2str(dataStruct(i).SAE_J2012_FTB);
concat = strcat(b, c);
targetStruct(i).name = concat;
% Create Simulink.Parameter object
paramObj = Simulink.Parameter;
paramObj.Value = targetStruct(i).name;
targetStruct(i).paramObj = paramObj;
end
In this code, after concatenating the variables 'b' and 'c', a 'Simulink.Paramete'r object 'paramObj' is created and assigned the concatenated value. Then, the 'paramObj' is added as a field 'paramObj' to the 'targetStruct' structure.
Please note that the functionality of converting 'string' to 'Simulink.Parameter' object as been introduced in MATLAB R2023b. I have verified the above code in the aforementioned release and it might produce some error in the previous releases. If you are using a previous release, I would suggest you to upgade to MATLAB R2023b to convert 'string' values to 'Simulink.Parameter'. Here is the MATLAB Socumentation for the same:
0 Comments
See Also
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!