for- loop code embedded in MATLAB Function Block shows and out of bounds error....
1 回表示 (過去 30 日間)
古いコメントを表示
Hi all ... I have the following code embedded in matlab function block :
function MQRS = MQRSGENERATOR(abd1)
%#codegen
TMP=0;
for i=1:2500
if abd1(i)>30
TMP(i-10:i+10,1)=abd1(i-10:i+10);
elseif abd1(i)<-30
TMP(i-10:i+10,1)=abd1(i-10:i+10);
else
TMP(i,1)=0;
end
end
MQRS=TMP
But the Simulation Diagnostics shows me an error message saying:Simulation stopped due to out of bounds error. Block (#37) While executing: none ....
I don't know why is that.Any one knows how to fix the problem please help.Thanks in advance.
0 件のコメント
回答 (1 件)
Seyhan Emre Gorucu
2012 年 8 月 6 日
You abd and TMP variables have a size. Let's say that both are 2500*2500. If i=2500, then it is possible that MATLAB will look for abs1(2490,2510) in one of these lines. As abs1 does not have 2510 columns it says out of boundary.
2 件のコメント
Kaustubha Govind
2012 年 8 月 7 日
Also, when i=1, you are indexing into abd1(-9:11);
Once you have fixed the indexing issue, you may also need to preallocate the variable TMP (Embedded MATLAB does not support dynamically growing matrices like MATLAB does):
TMP=zeros(size(abd1));
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!