Slow excecution of MATLAB function when using filter2
1 次查看(过去 30 天)
显示 更早的评论
I am building a SIMULINK system for simulating a collision avoidance system for an AUV. For a part of the system I am creating a local map of the surroundings of the vehicle, based on sonar measurements.
To do this, I use a large matrix (1201 by 601) to reprecent the surroundings (120 by 60 meters, and 0.1 meter resolution). I draw the data from the sonar measurements as a line in this matrix. To create a padding around the detected obstacles I filter the matrix using the filter2 function with a circular filter.
This works like a charm, and runs fast (40 ms-ish) when writing and debugging the code in a matlab script. The problem is that when i run the excact same code as a part of a matlab function in SIMULINK, it runs really slow (minutes).
To make an example, I tested the following code:
A = magic(1000);
dres = 0.1;
pad2 = 3;
hfilt2 = fspecial('disk',round(pad2/dres));
mapDistance = filter2(hfilt2,A);
When running this code in a matlab script, it uses about 300ms to run. When including this code in a matlab function block in SIMULINK, it takes minutes to excecute the last line.
I observed that a file called "CompleteModel_sfun.mex" (my SIMULINK model is called "CompleteModel") in the current matlab folder gets much larger when including the code in SIMULINK. From about 3 MB to 19 MB. I guess this should be a hint, but it's not clear to me..
0 个评论
回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!