for- loop code embedded in MATLAB Function Block shows and out of bounds error....
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Seyhan Emre Gorucu
on 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 Comments
Kaustubha Govind
on 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));
See Also
Categories
Find more on Simulink Functions in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!