Matlab DPIGEN- dynamic arrays

We are looking to move our UVM DPI linked C models to Matlab models. We have had some success using the matlab dpigen function to export Matlab functions.

For example, I write a Matlab function to average the numbers in the input

function ave = average(x) %#codegen
ave = sum(x(:))/numel(x);
end

I then can say

i= [0 1 100]
average(i)
ans =
33.6667

Simple enough. Now I export that to a Systemverilog DPI call…

dpigen average -args double(ones(1,3))

Matlab done. I look at the output package file…

import “DPI-C” function void DPI_average(input chandle objhandle,input real x [3],output real ave);

So I specified a width of 3 for the input- and I got it. Great.

How do I specify the input to be a dynamic array? I don’t know what size I want? One way would be to specify the range to be long and make another input with the size— but ultimately we want to send and receive sample data from Matlab.

In reply to wpiman:

We are looking to move our UVM DPI linked C models to Matlab models. We have had some success using the matlab dpigen function to export Matlab functions.
For example, I write a Matlab function to average the numbers in the input
function ave = average(x) %#codegen
ave = sum(x(:))/numel(x);
end
I then can say
i= [0 1 100]
average(i)
ans =
33.6667
Simple enough. Now I export that to a Systemverilog DPI call…
dpigen average -args double(ones(1,3))
Matlab done. I look at the output package file…
import “DPI-C” function void DPI_average(input chandle objhandle,input real x [3],output real ave);
So I specified a width of 3 for the input- and I got it. Great.
How do I specify the input to be a dynamic array? I don’t know what size I want? One way would be to specify the range to be long and make another input with the size— but ultimately we want to send and receive sample data from Matlab.

In system verilog you can use the dynamic array
int a // dynamix array and c-side you can use the svopenArrayHandle that handles the dynamic array on your c-side .

In reply to kddholak:

We have been using SystemVerilog Dynamic array along side svOpenArrayHandles in our C code to pass array between C and SV.

That isn’t the concern.

The problem is we don’t know how to get Matlab to generate dynamic arrays on its exported DPI packages…