Simulink Code Generation Error: Array of Classes Initalization
Hello,
I am trying to built a Simulink function which keeps record of the statistics of the system by using array of classes. However, I can not generate an array of class in Simulink. I realize that I should instantiate an array in Simulink but how can I instantiate a class?
arrivedArray(3, 65536) = queueInfo;
analysisArray(3, 65536) = queueInfo;
In the picture above, queueInfo is my class. This two lines return with the following error.
Code generation requires variable arrivedArray to be fully defined before subscribing it.
By the way, this is the suggested method by Matlab for creating an array of class but somehow it doesn’t work. Later I’ve tried this one:
persistent arrivedArray
if isempty(arrivedArray)
arrivedArray(3, 655336) = queueInfo;
end
persistent analysisArray
if isempty(analysisArray)
analysisArray(3, 65536) = queueInfo;
end
But it doesn’t work either. The error İs:
Persistent variable ‘arrivedArray’ must be assigned before it is used. The only exception is a check using ‘isempty(arrivedArray)’ that can be performed prior to assignment.
I understand the error but have no idea how to fix it. A constructor did not help me too. Here is my class structure:
1
classdef transactionInfo
properties
tag = uint16(0);
arrivalTime = uint64(0);
departureTime = uint64(0);
end
methods
function obj = transactionInfo(v)
if nargin > 0
obj.tag = uint16(v);
obj.arrivalTime = uint64(v);
obj.departureTime = uint64(v);
end
end
end
end
2
classdef queueInfo < transactionInfo
properties
length = uint16(0);
queueID = uint8(0);
delay = uint64(0);
end
methods
function obj = queueInfo(v)
if nargin > 0
obj.length = uint16(v);
obj.queueID = uint8(v);
obj.delay = uint64(v);
end
end
end
end
Does anyone know how to fix this issue?
Note: There might be some obvious errors in my class structures, I am kind of new to OOP. Every suggestion is welcomed.Hello,
I am trying to built a Simulink function which keeps record of the statistics of the system by using array of classes. However, I can not generate an array of class in Simulink. I realize that I should instantiate an array in Simulink but how can I instantiate a class?
arrivedArray(3, 65536) = queueInfo;
analysisArray(3, 65536) = queueInfo;
In the picture above, queueInfo is my class. This two lines return with the following error.
Code generation requires variable arrivedArray to be fully defined before subscribing it.
By the way, this is the suggested method by Matlab for creating an array of class but somehow it doesn’t work. Later I’ve tried this one:
persistent arrivedArray
if isempty(arrivedArray)
arrivedArray(3, 655336) = queueInfo;
end
persistent analysisArray
if isempty(analysisArray)
analysisArray(3, 65536) = queueInfo;
end
But it doesn’t work either. The error İs:
Persistent variable ‘arrivedArray’ must be assigned before it is used. The only exception is a check using ‘isempty(arrivedArray)’ that can be performed prior to assignment.
I understand the error but have no idea how to fix it. A constructor did not help me too. Here is my class structure:
1
classdef transactionInfo
properties
tag = uint16(0);
arrivalTime = uint64(0);
departureTime = uint64(0);
end
methods
function obj = transactionInfo(v)
if nargin > 0
obj.tag = uint16(v);
obj.arrivalTime = uint64(v);
obj.departureTime = uint64(v);
end
end
end
end
2
classdef queueInfo < transactionInfo
properties
length = uint16(0);
queueID = uint8(0);
delay = uint64(0);
end
methods
function obj = queueInfo(v)
if nargin > 0
obj.length = uint16(v);
obj.queueID = uint8(v);
obj.delay = uint64(v);
end
end
end
end
Does anyone know how to fix this issue?
Note: There might be some obvious errors in my class structures, I am kind of new to OOP. Every suggestion is welcomed. Hello,
I am trying to built a Simulink function which keeps record of the statistics of the system by using array of classes. However, I can not generate an array of class in Simulink. I realize that I should instantiate an array in Simulink but how can I instantiate a class?
arrivedArray(3, 65536) = queueInfo;
analysisArray(3, 65536) = queueInfo;
In the picture above, queueInfo is my class. This two lines return with the following error.
Code generation requires variable arrivedArray to be fully defined before subscribing it.
By the way, this is the suggested method by Matlab for creating an array of class but somehow it doesn’t work. Later I’ve tried this one:
persistent arrivedArray
if isempty(arrivedArray)
arrivedArray(3, 655336) = queueInfo;
end
persistent analysisArray
if isempty(analysisArray)
analysisArray(3, 65536) = queueInfo;
end
But it doesn’t work either. The error İs:
Persistent variable ‘arrivedArray’ must be assigned before it is used. The only exception is a check using ‘isempty(arrivedArray)’ that can be performed prior to assignment.
I understand the error but have no idea how to fix it. A constructor did not help me too. Here is my class structure:
1
classdef transactionInfo
properties
tag = uint16(0);
arrivalTime = uint64(0);
departureTime = uint64(0);
end
methods
function obj = transactionInfo(v)
if nargin > 0
obj.tag = uint16(v);
obj.arrivalTime = uint64(v);
obj.departureTime = uint64(v);
end
end
end
end
2
classdef queueInfo < transactionInfo
properties
length = uint16(0);
queueID = uint8(0);
delay = uint64(0);
end
methods
function obj = queueInfo(v)
if nargin > 0
obj.length = uint16(v);
obj.queueID = uint8(v);
obj.delay = uint64(v);
end
end
end
end
Does anyone know how to fix this issue?
Note: There might be some obvious errors in my class structures, I am kind of new to OOP. Every suggestion is welcomed. simulink, class, code generation MATLAB Answers — New Questions