01-25-2009 05:44 PM
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.
01-25-2009 07:05 PM
01-26-2009 07:00 AM
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
01-26-2009 08:20 AM
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)
01-26-2009 08:53 AM
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.
01-26-2009 12:07 PM
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/
11-25-2010 09:54 AM
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
}
}