How to fix Non-constant expression or empty matrix

1 次查看(过去 30 天)
Help me please.
There is any different between following codes?
Case 1:
m_intrlvr = zeros(10,1);
m_intrlvr(1) = 4;
m_intrlvr(2) =7;
m_intrlvr(3) =10;
m_intrlvr(4) =3;
m_intrlvr(5) =6;
m_intrlvr(6) =9;
m_intrlvr(7) =2;
m_intrlvr(8) =5;
m_intrlvr(9) =8;
m_intrlvr(10) =1;
persistent hTBCode;
if isempty(hTBCode )
hTBCode = comm.TurboEncoder('TrellisStructure', ...
poly2trellis(4,[13 15], 13), 'InterleaverIndices', m_intrlvr);
end
Case 2:
m_intrlvr = [4;7;10;3;6;9;2;5;8;1];
persistent hTBCode;
if isempty(hTBCode )
hTBCode = comm.TurboEncoder('TrellisStructure', ...
poly2trellis(4,[13 15], 13), 'InterleaverIndices', m_intrlvr);
end
The first case it raise error: Non-constant expression or empty matrix. This expression must be constant because its value determines the size or class of some expression. Internal Error: This error occurred inside a MathWorks function.
P-code function 'pvparse.p' produced an error.
but the second one it is ok. anyone can help me where is my wrong?
(Re-opened)
  4 个评论
Walter Roberson
Walter Roberson 2012-7-8
Then I suspect it is trying to do code generation and that the code needs to conform to the Embedded MATLAB standards.
My (weak) knowledge is that m_intrlvr = zeros(10,1) should work for that situation. It would, however, not necessarily work if really the code was
numvals = 10;
m_intrlvr = zeros(numvals, 1);
Though it might in that particular case as it can see numvals as a constant. If the number of values was being passed through a signal then it would not work.
Which MATLAB version are you using? I have a vague memory of someone mentioning a bug in the automated code generation, a small number of releases ago.
San
San 2012-7-8
编辑:Walter Roberson 2012-7-9
>Which MATLAB version are you using?
I'm working with R2011b
it look better when put the script in separately function file. Thanks for your supporting.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Error Detection and Correction 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by