- Permitting your user to choose only one of a limited number of widths and build distinct subsystems for every permitted width that hold all of the blocks that need to know about that width, with the block boundaries at the point where the computations no longer rely upon the width;
- Variant controls https://www.mathworks.com/help/simulink/ug/switching-between-variants.html
- there might be options about busses that carry around the length and an array of bytes and then at each point you switch on the length to choose the appropriate instruction and push the results back into a bus again.
Cannot use input value with 'numerictype' in MATLAB Fcn
1 次查看(过去 30 天)
显示 更早的评论
The code below works fine
function y = fcn(u)
word_length = u.WordLength;
bin_pt = 5;
T = numerictype(1,word_length, bin_pt);
y = reinterpretcast(u,T);
But I want user-defined binary point and when I take it as an input (from a mask variable or a constant) it doesn't
function y = fcn(u, bin_pt)
word_length = u.WordLength;
% bin_pt = 5;
T = numerictype(1,word_length, bin_pt);
y = reinterpretcast(u,T);
This gives the following error
0 个评论
回答(1 个)
Walter Roberson
2019-5-15
Every signal in Simulink must be of specific type, and fixed point values of different length are considered different data types. The consistency checking is done at the time the model is to be built, but the building process compiles in specific internal routines and lengths.
Options include:
3 个评论
Walter Roberson
2019-5-15
function y = fcn(u)
switch u.WordLength
case 1
T = numerictype(1, 1, 5);
case 2
T = numerictype(1, 2, 5);
case 3
T = numerictype(1, 3, 5);
case 4
T = numerictype(1, 4, 5);
case list off all of the other user possibilities individually
end
y = reinterpretcast(u,T);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Fixed Point 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!