MATLAB: Simulink “Find block” HDL Coder

code generationdigital image processingdigital signal processinghdlHDL CoderMATLABsignal processingsimulink

How can I use HDL compatible blocks to portray the "find block" functionality. http://uk.mathworks.com/help/simulink/slref/find.html#bsdkmvh-8
Unfortunately the find block is not HDL compatible, so there must be other ways to output an index based on a condition. I have the Matlab code:
idx = find(gs >= g, 1, 'last')
that I need to simulate in Simulink with HDL coder and I don't think a user defined function block will work as it will just contain find() which is not HDL compatible. Thanks for your help in advance.

Best Answer

I believe this is answered with the other question you posed on the break command. See how idx is a persistent value - that means it stores its value across calls. If you choose to update only when idx is 0, you get the the first value of gs >= g. If you update all the time you get the last value.
You can make this work for a 2D case as well.
In general, you should avoid having all these comparisons in a for loop. The entire for loop will run in one "clock", so your FPGA code will run very slowly. You are better off streaming the gs values in one at a time and taking one "clock" to compare one value of gs to g (the second code example in my answer to your other question ).
Related Question