- An index counter (persistent variable)
- two persistent variables for the index (index_max1, index_max2)
- two persistent variables for the max values (value_max1, value_max2)
- You compare the input_val with value_max2 and value_max1
- You assign value_max1 to value_max2 and index_max1 to index_max2 if input_val > value_max1 and then the input_val to value_max1 and index_count to index_max1
- ...
- ...
- You output results and reset all persistent variables to 0 if counter reaches max index value (e.g. 4096)
Using a persistent variable array in MATLAB function for HDL Coder
13 views (last 30 days)
Show older comments
I have MATLAB function which calculates the two maximum numbers in an array of 4096 elements. I have a persistent array - of int32 numbers - which receives a single element from the function block and assigns it to the corresponding index. However when I try to build HDL for the subsystem that contains the MATLAB function. I receive the error "The persistent variable 'array_per' in chart '....' is of non-integer type. The option 'Support floating-point numbers' has not been set Code Genaration configuration options.
Is there a way to fix that?
0 Comments
Answers (1)
Tom Richter
on 5 Dec 2023
Hi Kaan,
it would be good if you could share your MATLAB code you try to implement using the MATLAB Function block. For me it sounds like a wrong data type setting. The array should be initialized like this:
persistent array_per
if isempty(array_per)
array_per = zeros(4096,1,'int32');
end
The array will keep the data type as long as you index only one element:
array_per(4) = input_val;
Such a big array is better implemented using RAM (only one read/write action per function call).
I also doubt that you need such a big persistent variable to get the two most max values. I would use:
The rest is simple I guess.
I hope that helps,
Tom
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!