Simulink Block IO signal data type reference inside the fcn block

Dear experts,
Just wondering if it is possible to reference I/O data type specified in "Edit Data" inside a fcn block, while doing value assignment.
For example, input "u" is defined as "fixdt(1,9,0)" in "Ports and Data Manager". Currently I have to do this explicitly: "u = fi(3, 1, 9, 0)" if I wanna say "u=3".
I am thinking it will be convenient if I could just do "u = fi(3, numerictype(u))".
Thanks,

7 Comments

Using "u = fi(3, numerictype(u))" works for me. Are you seeing an error?
'u = fi(3, numetictype(u))'
Error: Undefined function or variable 'u'. The first assignment to a local variable determines its class.
'u' is defined as fixdt(0,3,0) in Ports and Data Manager.
I tested moving the fcn block into a different model, and found out, if the input signal is set to Type = "Inherit: Same as Simulink" the numerictype can be dereferenced inside the fcn block, but not from explicit definition in side 'Ports and Data Manager'.
legendbb: It works for me both when the input type is set to "Inherit" or when it is explicitly specified. What error do you get in the second case?
Hi, Kaustubha,
Thanks for your comment.
I am not able to reproduce the same error, after rewriting all those functions to 'u=fi(3,numerictype(u))' and redesign the whole block.
But clearly previous error of 'u=fi(3,numerictype(u))" is
Error: Undefined function or variable 'u'. The first assignment to a local variable determines its class.
Please leave this ticket here for notes, it might come back and I will update it here.
Thanks,
"Error: Undefined function or variable 'u'. The first assignment to a local variable determines its class." - this means that "u" is not defined as ta local/input variable in the function. I assumed "u" was your input because you posted the 'u=fi(3,numerictype(u))' line originally as a desirable syntax.
Hi, Kaustubha,
Originally, I might confused myself by trying to reference data type for output. I knew for sure it generates the abovementioned error, if I define explicitly data type for "output y" and try to reference its data type inside fcn code, for instance:
function y = f(u)
reg_y = fi(0,numerictype(u));
y = reg_y;
end

Answers (0)

This question is closed.

Products

Asked:

on 26 Feb 2013

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!