New fields cannot be added when structure has been read or used, MATLAB coder.
42 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I am trying to convert my matlab project into C++ using MATLAB Coder. I have a Class and in the constructor, I am initializing all the values of the struct that I have declared in the properties. The code goes something like this.
classdef ZCNET
properties
ZCNET_cfg;
z_own_turbo_param_2bit_base;
trellis;
end
methods
function self = ZCNET()
self.ZCNET_cfg.AP_ANT_NUM = 1;
self.ZCNET_cfg.NODE_ANT_NUM = 1;
self.ZCNET_cfg.useLTETurbo = 1;
self.ZCNET_cfg.USE_SIMIC = 1;
self.ZCNET_cfg.ANT_NUM = self.ZCNET_cfg.AP_ANT_NUM;
if 1
load_perm = load ('ZCNET_permutations.mat'); % NOTE: to get load_perm.ZCNET_permutations. load_perm.ZCNET_permutations{100} has a random permutation of 100 numbers
else
for h=1201:1500
load_perm.ZCNET_permutations{h} = randperm(h);
end
load_perm.ZCNET_permutations_rev = cell(1,length(load_perm.ZCNET_permutations));
.
.
.
.
.
Since I cannot convert a class directly, I have this function that create an object of the class and them I am using the object to display some valies. This is a test code in order to fix this issue. The function looks something like this.
function call_zcnet()
zc1 = ZCNET;
x = zc1.ZCNET_cfg;
disp(x.bandwidth);
disp(x.permutations{1,5});
end
I am passing "call_zcnet.m" to the coder but when it is giving quiet a few errors. I can run the code by callign 'call_zcnet' from the command window without any problem but coder is giving me following run-time issues.
Any help is appreciated.
Thank you.
2 件のコメント
Denis Gurchenkov
2021 年 6 月 15 日
Hi Raghav, the screenshot you created does not contain the actual text of the errors.
Maybe you can just attach a zip file with all the files that one needs in order to reproduce the error? It'll be easier for someone to offer suggestions if the issue can be reproduced.
回答 (1 件)
Darshan Ramakant Bhat
2021 年 6 月 16 日
If you want to make this class codegen compatible, you will have to make the field as a struct type. Below is a sample modified code ;
classdef ZCNET
properties
ZCNET_cfg = struct('AP_ANT_NUM',1,'NODE_ANT_NUM',3,'useLTETurbo',1,'USE_SIMIC',1);
end
methods
function self = ZCNET() %constructor
self.ZCNET_cfg.AP_ANT_NUM = 1;
self.ZCNET_cfg.NODE_ANT_NUM = 3;
self.ZCNET_cfg.useLTETurbo = 1;
self.ZCNET_cfg.USE_SIMIC = 1;
end
end
end
Hope this will be helpful.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!