From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Concatenate arrays?

what function i must use to concatenate two 'double' arrays?
0 Kudos
Message 1 of 6
(2,986 Views)
CVI does not have any functions for that, but its something you can do really easily.

One =(double*) calloc (10, sizeof(double));
for(panelHandle =0; panelHandle<10;panelHandle++)
One[panelHandle]=panelHandle;

Two =(double*) calloc (10, sizeof(double));
for(panelHandle =0; panelHandle<10;panelHandle++)
Two[panelHandle]=20*panelHandle;

One =(double*) realloc (One, 20*sizeof(double)); //realloc the memory for the first array so it can accomodate the array we will concatenate.
memcpy (&One[10], Two, 10*sizeof(double)); //do a block copy of the second array into the first array

remember to free the memory after you're done using it.

Hope this helps

Bilal Durrani
NI
Bilal Durrani
NI
0 Kudos
Message 2 of 6
(2,986 Views)
thanks for answering me,
i`m using CVI 5.5 i don`t think it has 'sizeof' function.
another thing,One and two are my double arrays right?
for example if I already have two full double arrays Data[200] and Array[200],should it look like that?

Data =(double*) calloc (200, sizeof(double));
for(panelHandle =0; panelHandle<200;panelHandle++)
Data[panelHandle]=panelHandle;


Array =(double*) calloc (200, sizeof(double));
for(panelHandle =0; panelHandle<200;panelHandle++)
Array[panelHandle]=400*panelHandle;


Data =(double*) realloc (One, 400*sizeof(double)); memcpy (&Data[200], Array, 200*sizeof(double));

so Data now includes the initial 'Data' and 'Array'?
0 Kudos
Message 3 of 6
(2,986 Views)
yes, One and Two are defined as follows

double *One=NULL;
double *Two=NULL;

Sorry, should have added that.

Im pretty sure CVI 5.5 has the sizeof function. It returns the number of bytes associated with a datatype.

You will need to dynamically allocate an array, not used a fixed size array like Data[200]. You cannot resize at runtime a fixed size array.

By defining pointers to arrays instead of a fixed size array, I can resize the memory allocated for the array however I like,allowing me to concatenate an array by changing its size.

Bilal
Bilal Durrani
NI
0 Kudos
Message 4 of 6
(2,986 Views)
ok , now it`s more clear to me.
just one more thing, how to assign a variable into the dynamic array,i mean like I did with fixed size arrays:
for(i=0;i<100;i++)
Data[i]=x;

thanks alot!
Ken
0 Kudos
Message 5 of 6
(2,986 Views)
the dynamic array works in the same way as the static array. Just use a for loop with a indexer like you showed in your post.

Bilal
Bilal Durrani
NI
0 Kudos
Message 6 of 6
(2,986 Views)