how to convert structure variables into a simulink.parameter object
조회 수: 6 (최근 30일)
이전 댓글 표시
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
답변 (1개)
R
2024년 3월 26일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!