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

1 Ansicht (letzte 30 Tage)
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.

Antworten (1)

Seyhan Emre Gorucu
Seyhan Emre Gorucu am 6 Aug. 2012
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 Kommentare
Kaustubha Govind
Kaustubha Govind am 7 Aug. 2012
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 am 9 Aug. 2012
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Simulink Functions finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by