Help on User Defined Function

1 回表示 (過去 30 日間)
John
John 2014 年 8 月 13 日
回答済み: Mike Hosea 2014 年 9 月 19 日
I'm Getting this Could not determine the size of this expression. error in a very simple function, if someone can check it out and give me a hint, I would appreciate it.
The code is this:
function subPortadora = codigos(txSig,i)
%#codegen
temp = complex(zeros(15,1));
if i < 512
if i==0
temp = txSig(1:15,1);
else
temp = txSig(i*15+1:15*(i+1),1);
end
end
subPortadora = temp;
Thanks in Advance
  1 件のコメント
Adam
Adam 2014 年 8 月 13 日
編集済み: Adam 2014 年 8 月 13 日
Presumably the error message points to a specific line of the code?
It would help to know what form txSig is expected to take. Judging by the code it looks like it should be an array of at least 7680 values in the first dimension?

サインインしてコメントする。

回答 (2 件)

Nathan
Nathan 2014 年 8 月 13 日
編集済み: Nathan 2014 年 8 月 13 日
Why don't you just simply replace your call to codigos with:
txSig(i*15+1:15*(i+1),1)
This will still return a column vector pulled from txSig. My solution assumes that i>=0 & i<513 and is an integer.
Alternatively, if you do need the funciton check out this link with what appears to be the same problem: http://www.mathworks.com/matlabcentral/answers/92878-why-does-embedded-matlab-fail-to-detemrine-the-size-of-my-expression-in-simulink-7-2-r2008b

Mike Hosea
Mike Hosea 2014 年 9 月 19 日
Sorry we missed this question. The problem is that colon expression lengths are tricky business in MATLAB because the end point of a:b:c is not required to equal a + n*b for any integer n, and the situation is even more complicated with non-integer or extremely large values when there can also be round-off error. Try replacing
temp = txSig(i*15+1:15*(i+1),1);
with
temp = txSig(i*15+(1:15),1);
The latter makes it crystal clear that the indexing expression is 15 elements long. You shouldn't need the if/else, as that should work perfectly when i == 0.

カテゴリ

Help Center および File ExchangeMATLAB Coder についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by