Cannot use input value with 'numerictype' in MATLAB Fcn

조회 수: 1 (최근 30일)
M. Saad
M. Saad 2019년 5월 12일
댓글: M. Saad 2019년 5월 20일
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
matlab_error.PNG

답변 (1개)

Walter Roberson
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:
  • 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.
  댓글 수: 3
Walter Roberson
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);
M. Saad
M. Saad 2019년 5월 20일
I think I couldn't make myself clear, my case was otherwise. However, I have solved it as following, might it help someone.
I used Data Type Propagation block with a Data Type Conversion block. Input is at Ref 1 to keep the number of bits same and Ref 2 is provided by the constant block whose signedness and binary point I can modify according to the user input. In Data Type Propagation block one can parameterize which things to change from which references.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Fixed Point에 대해 자세히 알아보기

제품


릴리스

R2016b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by