取消
显示结果 
搜索替代 
您的意思是: 

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 项奖励
1 条消息(共 7 条)
12,027 次查看
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 项奖励
2 条消息(共 7 条)
12,017 次查看

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 项奖励
3 条消息(共 7 条)
11,973 次查看

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)

 

 

4 条消息(共 7 条)
11,962 次查看

 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. 

 

5 条消息(共 7 条)
11,956 次查看

Hi Ping,

 

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

 

https://www.ni.com/docs/en-US/bundle/labview/page/formula-node-and-expression-node-functions.html

0 项奖励
6 条消息(共 7 条)
11,930 次查看

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 项奖励
7 条消息(共 7 条)
11,390 次查看