Simulink - Embedded Matlab function - Size of function not bounded
显示 更早的评论
Hi all,
I am trying to use an embedded Matlab function block to calculate a time delay such as: x(t) - x(t - tn) = constant
My code is below where 'x' and 't' are input vectors of 21x1 (created using the 'Tapped Delay' block) and I require 'tn' as a scalar output.
function tn = fcn(x, t)
tn = zeros(1, 'double'); %#ok<*PREALL>
if x(end) < 1
tn = 1.1;
return
end
coder.extrinsic('csapi', 'fnval')
coder.varsize('tn', 1)
tq = min(t):0.001:max(t);
b = csapi(t, x);
xq = zeros(size(tq), 'double');
xq = fnval(b, tq);
a = xq(end) - xq - 1;
idx = find(min(abs(a)) == abs(a), 1, 'last');
tn = tq(end) - tq(idx(1));
So the first error I was getting was: Data 'tn' (#62) is inferred as a variable size matrix, while its specified type is something else.
I'm not 100% sure why this error is occurring because I would assume 'tn' would always be scalar, well that's my intention. However, I set 'tn' as a variable size matrix but set its size to '1'.
The next error: Dimension 2 is fixed on the left-hand side but varies on the right ([1 x 1] ~= [1 x :?]).
I looked here (<http://uk.mathworks.com/matlabcentral/answers/79386>) but I couldn't see any option to make the variable 'Tunable'.
So instead another thread (<http://uk.mathworks.com/matlabcentral/answers/154282>) mentioned changing the 'tq(idx)' to 'tq(idx(1))'.
But now I'm stuck at the following error: Computed maximum size of the output of function 'colon' is not bounded. Static memory allocation requires all sizes to be bounded. The computed size is [1 x :?].
Function 'MATLAB Function1' (#60.182.201), line 12, column 6: "min(t):0.001:max(t)"
One thread (<http://uk.mathworks.com/matlabcentral/newsreader/view_thread/310599>) mentioned using the assert function but I have had no luck with this.
Anyone know of a potential fix? Or have I just missed something prior to my other fixes that would also work?
Cheers Carl
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Spline Postprocessing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!