The summary of my question is I need know how to preallocate an array of custom objects in a way that is compatible with Simulink when using the Matlab Function block in Simulink.
pulse_array(1:2,1:4) = pulse;
pulse_array = pulse; for i = 1:2 for j = 1:4 pulse_array(i,j) = pulse; end end
classdef pulse properties A %Amplitude end methods function obj = pulse(A) if nargin>0 %Allows for array construction https://www.mathworks.com/help/matlab/matlab_oop/initialize-object-arrays.html obj.A = A; end end end end
ANSWER
Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.
According to the documentation for MATLAB Classes for Code generation, creation of arrays of objects is not supported yet. As a workaround, you could define a cell - array to store the objects, as such:
pulse_array = cell(2,4); for idx = 1 : 8 pulse_array{idx} = pulse; end pulse_array = 2×4 cell array {1×1 pulse} {1×1 pulse} {1×1 pulse} {1×1 pulse} {1×1 pulse} {1×1 pulse} {1×1 pulse} {1×1 pulse}
Comments
Post a Comment