This widget could not be displayed.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to find the size of 2D input array in formula node

I have two questions about array manipulation in LabView.

 

1. How to find the size of 2D array in formula node? this 2D array xx is passed to the input of a formula node, inside the formula node, I tried to find out the size (row and column number) of this 2D array using code below:

 

colnum = sizeof(xx[0]) /sizeof(xx[0][0]);

 

rownum = sizeof(xx) /sizeof(xx[0]);

 

the logic is, xx[0] should be the 1st row (1D array), sizeof(xx[0]) should give the row array's total size, sizeof(xx[0][0]) is the size of each element in the 1st row, dividing them should get the column elements number.

 

similarly,  sizeof(xx) divided by sizeof(xx[0]) give the row number.

 

but my code get a syntax error, it can not recognize the sizeof function.

 

I also tried the following code:

 

colnum = xx[1] - xx[0];

 

the logic is, xx[0] should be the 1st row starting address, xx[1] should be the 2nd row starting address, their difference should be the size of elements in the 1st row,  my code still get a syntax error. If I add address operator & in front of xx, it still generate error message.

 

2. I have a 2D floating number array, size of 4000X2, that is, 4000 rows, 2 columns, each row represent a data point (x, y), where x is the 1st column element, y is the 2nd column element.

 

I need to use this 2D array to do simple interpolation, while the 1D array interpolation function requires an input of 1D array of points (x, y).

 

I do not know how to create "point" in LabView, that is, I need to convert this 2D number array (4000X2) into 1D array of points,

 

can anyone give a clue? or a sample VI for doing this conversion is better.
0 Kudos
Message 1 of 7
(11,154 Views)
Use the Array Size function on your block diagram for your 2D array. It will return a 1D array, where the first element is the number of rows, the second element the number of columns. Pass this data into the Formula Node as extra input variables, rather than trying to determine the size in the Formula Node itself.
Jarrod S.
National Instruments
0 Kudos
Message 2 of 7
(11,144 Views)

Thanks, Jarrod.

 

1. Yes, I know that the array size function outside of formula node works. I am just curious if there is a way to do it inside the formula node.

 

2. What about the 2D number array conversion to 1D points array?

 

ping

0 Kudos
Message 3 of 7
(11,100 Views)

This works for me (nr=number of rows, nc=number of columns):

 

 nr=sizeOfDim(Array,0);

nc=sizeOfDim(Array,1);

 

and if you want it in MathScript: 

 

[nr,nc]=size(Array)

 

 

Message 4 of 7
(11,089 Views)

 2. I have a 2D floating number array, size of 4000X2, that is, 4000 rows, 2 columns, each row represent a data point (x, y), where x is the 1st column element, y is the 2nd column element.


Either:

- change this array to 2 seperate arrays (x and y) earlier in the program.

- Split the array whenever you need to access just x or y using "Array subset" and "Reshape array"

 

 I'd go with the first, since it seems the more logical approach, but I don't know how much you'd have to redo. 

 

Message 5 of 7
(11,083 Views)

Hi Ping,

 

Use this link as a reference to the Formula Node Syntax:

 

http://zone.ni.com/reference/en-XX/help/371361E-01/lvhowto/formula_node_and_express/

0 Kudos
Message 6 of 7
(11,057 Views)

The code is given below...Its in C

#include <stdio.h>
#include <conio.h>

int main()
{
int array1[3][4],array2[3][4]; //array default size of array taken as 3 x 4
int result[3][4];

int i,j;

for (i=0;i<3;i++)
{
for (j=0;j<4;j++)
{
printf("\nArray1:: Enter element at loc %d x %d\t",i+1,j+1);
scanf("%d",&(array1[i][j]));
}
}


for (i=0;i<3;i++)
{
for (j=0;j<4;j++)
{
printf("\nArray2:: Enter element at loc %d x %d\t",i+1,j+1);
scanf("%d",&(array2[i][j]));
}
}

for (i=0;i<3;i++)
{
for (j=0;j<4;j++)
{
result[i][j] = array1[i][j] + array2[i][j];
}
}

printf("\nThe resulting array is\n");

for (i=0;i<3;i++)
{
for (j=0;j<4;j++)
{
printf("%d\t",result[i][j]);
}
printf("\n"); //Next line
}

}

 

 

 

tampa web design

0 Kudos
Message 7 of 7
(10,517 Views)