Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Passing a single row of a 2d array as a parameter

Status
Not open for further replies.

ghostridergr

Member level 1
Joined
Nov 22, 2011
Messages
41
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,590
In order not to open a new thread can anyone help me on this: what if i want to pass as an argument a whole single row of a 2d array. I am calling my function something like this but i get error . This is my code:

Code:
match(k)<=find_min(k,0 to 3);

I want to avoid using a for loop. Is there any way of doing it at once?

I am getting those errors:
Code:
** Error: C:/Modeltech_pe_edu_10.0a/examples/matlab_eq.vhd(91): Range cannot be actual parameter.
** Error: C:/Modeltech_pe_edu_10.0a/examples/matlab_eq.vhd(91): No feasible entries for subprogram "find_min".

and my function definition is this:
Code:
function find_min(row: in big_matrix(0 to 3)) return signed is
 

The programming language I use (BASIC) only returns one value from a one-line function. It only performs the operation once. It won't make it easy on me by performing it on an entire array automatically with one call.

In case the above doesn't apply in your case, here are possibilities to try. All take a few more cpu cycles.

* Pass the entire 2 dimensional array (if permitted in matlab)

* If the row is just 4 elements, then pass them as 4 variables: "find_min(k,0), find_min(k, 1), find_min(k, 2), find_min(k, 3)"

* Or just before you call the function: Create a 1-dimension array, then (using a For loop) set its values to the desired row in the 2-dim array. Then pass the 1-dim array only.
 

Brad - the OP questions refers to VHDL. In VHDL you can pass any type you like into a function, and return any type (including N dimensional arrays). But you cannot de-construct multi-dimensional array types ie: ones like this:

type my_array_t is array(0 to 10, 0 to 10) of integer;

You can only access the entire thing or one element if it (true for all array types). So for loops are inevitable if you want an entire row (and you'll have to create another type to store the temporary extracted data).

Why not just make an array of arrays, and then you can extract an entire "row" as its only a single element of the array:

type row_t is array(0 to 10) of integer;
type matrix_t is array(0 to 10) of row_t; --now this is just a 1d array, and each element is a 1d array.
signal matrix : matrix_t

a <= some_function(matrix(n) ); --passes an entire row to a function
 
Depending on the array structure, it may be possible to pass array slices to the function. But your syntax is simply wrong. If k is an array, the parentheses specifying a slice are missing.

I don't want to guess about the actual array definition, can you kindly tell it and the type specification of the function argument.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top