for- loop code embedded in MATLAB Function Block shows and out of bounds error....
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Seyhan Emre Gorucu
il 6 Ago 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 Commenti
Kaustubha Govind
il 7 Ago 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));
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!