フィルターのクリア

for- loop code embedded in MATLAB Function Block shows and out of bounds error....

2 ビュー (過去 30 日間)
Ahmed Tawfeeq
Ahmed Tawfeeq 2012 年 8 月 6 日
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.

回答 (1 件)

Seyhan Emre Gorucu
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
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));
Ahmed Tawfeeq
Ahmed Tawfeeq 2012 年 8 月 9 日
Hi...firstly, both abd1 and TMP are one column vector secondly , the data base I use ensures not to satisfy the condition before i approaches 10.... But I did not understand you when saying: you need to preallocate the variable TMP... TMP=zeros(size(abd1));
do you mean modifying the code to :
function MQRS = MQRSGENERATOR(abd1) %#codegen
TMP=0; TMP(1:2500)=0; for i=1:2500 if abd1(i,1)>30 TMP(i,1)=abd1(i,1);
elseif abd1(i,1)<-30
TMP(i,1)=abd1(i,1);
else
TMP(i,1)=0;
end
end
MQRS=TMP
I did that ,but nothing has changed.

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

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by