MATLAB Answers

Efficiency about Embedded Funtion in Simulink

1 view (last 30 days)
Lofi
Lofi on 19 May 2011
I have tried to write some Matlab Code in Simulink using "Embedded Function" Block. However I found that the efficiency is quite low, comparing to the Embedded function having same code in Demos which represented in Low fps in display.
I replaced the Embedded function in Demo with mine, same source code, and this problem appears more obvious. So could someone explain this to me? What can I do to improve this other than using S-Function which makes source code unreadable. Thanks~

  4 Comments

Show 1 older comment
Lofi
Lofi on 24 May 2011
The project I was study is "Chroma based road tracking", which can be found in Demos.
The embedded function I refer is "Project/Lane detection/FindValidPixels,../ufindMaximay,../ClearTopRight".
Here is the source Code of FindValidPixels:
function y = FindValidPixels(thr, u)
% This block supports the Embedded MATLAB subset.
% See the help menu for details.
[h, w] = size(u);
h_half = floor(h/2.0);
y = false(h, w);
for col = 1: w
row = 1;
acc = u(row, col);
while acc < thr && row <= h_half
y(row, col) = true;
row = row + 1;
acc = acc + u(row, col);
end
row = h;
acc = u(row, col);
while acc < thr && row > h_half
y(row, col) = true;
row = row - 1;
acc = acc + u(row, col);
end
end
What I mean is, after I replace this block with "Embedded Function block"(SAME SOURCE CODE WITH DEMO), the whole efficiency is decreased.
Arnaud Miege
Arnaud Miege on 24 May 2011
I have tried replacing the block with an Embedded MATLAB Function and copying the code across. I can't see any difference in performance. It works well in both cases.
Lofi
Lofi on 29 May 2011
I don't know whether this did not happened to yours. I tried replacing on the original demo, and I found efficiency decreasing happens most obvious when replacing the function works with overall matrix, such as 'Find valid Pixels' and 'ufindMaximay'. The Embedded Function block I use is 'Embedded MATLAB Function'.
I do curious about why this happens. But since this did not happens to your case, if there is no further help you could offer, thank you all the way. Thanks for your patience~

Sign in to comment.

Answers (1)

MarkB
MarkB on 23 May 2011
The best way to do this is probably to use Accelerator Mode, or Rapid Accelerator mode. There is some overhead that occurs during model update for these modes, but if the simulation is going to be repeated often enough, it can be worth it.

  0 Comments

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!