How to define size of class property depending on a given parameter (including codegen)
24 次查看(过去 30 天)
显示 更早的评论
I want to create a class, that is able to handle different property sizes depending on some configuration parameter, which is constant from beginning of the script or at compile time.
For Example, I would like to change the size (513) of the fft in this Class depending on configuration. The solution should work with matlab coder.
classdef FFT_Object
properties
FFT = complex(zeros([1 513],'single'),zeros([1 513],'single'));
end
function obj = FFT_Object()
end
end
回答(1 个)
Matt J
2025-11-5,18:11
编辑:Matt J
about 15 hours 前
With the classdef below, you can set the default size with its defaultSize() static method. This will remain in effect until the script is re-run. E.g.,
FFT_Object.defaultSize(1000);
new_obj=FFT_Object(); %default object of size 1x1000
classdef FFT_Object
properties
FFT
end
methods
function obj = FFT_Object(inputFFT)
if ~nargin
s=FFT_Object.defaultSize;
obj.FFT = complex(zeros([1 s],'single'),zeros([1 s],'single'));
else
obj.FFT=inputFFT;
end
end
end
methods (Static)
function varargout=defaultSize(n)
persistent siz
if isempty(siz), siz=513; end
if nargin, siz=n; end
if nargout, varargout={siz}; end
end
end
end
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!