How to define size of class property depending on a given parameter (including codegen)
27 ビュー (過去 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
2025 年 11 月 6 日 9:06
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!