Data is inferred as a variable size matrix, while its specified type is something else.

16 views (last 30 days)
Let "x" and "y" be two variable-size vectors. now i have a variable named "z" which is defined as:
function z=func(input)
% some code here
% x,y are not input
z = sum(x.*y')/sum(x);
end
obviously "z" is a double variable. but when i send it as the output of the function i get this error:
Data 'z' (#32) is inferred as a variable size matrix, while its specified type is something else.
I guess Simulink assumes that "z" is variable-size too. I'm stuck at this point. any suggestions?

Answers (1)

Walter Roberson
Walter Roberson on 29 Aug 2015
Before the final assignment to z, assign
z = 0;
This will tell Coder that the result is expected to be a scalar double.
  3 Comments
Marie Behzadi
Marie Behzadi on 30 Aug 2015
Edited: Marie Behzadi on 30 Aug 2015
not specifically. I just assign it to zero at first. I guess it will consider it as a double value; and then the result of calculation is always a double value. It's not a even vector or matrix but the error refers to a variable-size assignment!!

Sign in to comment.

Categories

Find more on Simulink Functions in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!