LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

2D array syntax @ formula node

Solved!
Go to solution

Hi guys,

I'm trying to figure out the formula node syntax for 2D-array. Anybody can help me on that.

 

my input is a 2D-array with x rows and 105 columns. The number of rows depends on my file.

I want to say all elements from 2 col, for instance, is equal to B.

 

In matlab for instance, I can write like that:

 

A = file(:;2);

 

What is the syntax for the formula node?

I can not use mathscripts because I dont have matlab installed in this PC.

 

Thanks

 

Kito

0 Kudos
Message 1 of 5
(5,716 Views)
Solution
Accepted by topic author Kitofelipe

Kitofelipe,

 

As I understand your question, you have a file with a 2D array of data of size [x,105] and you want to tease out an array of the second column [x,2]. 

There are two solutions for this:

 

Solution 1: Think outside the node!

You must be familiar with the array indexing node. You can just use that, and wire the column index as 2 to get your output array, as shown below.

 

Solution 2: If you still want the formula node syntax, here it is:

b[i] = a[i][1];

 

2d_array.JPG

 

I hope this solves the problem! Happy coding!

Prashanth N
National Instruments
Message 2 of 5
(5,706 Views)

The formula node is not Matlab-like syntax. It's more like C. Thus, you cannot use things like (:;2). You have to explicitly iterate through arrays, specifying full indexes. Thuse, for 2D arrays you'd have to say something like myArray[2][3].

 

You seem to be getting Matlab and MathScript confused. These are two different languages.

 

Matlab is distributed by MathWorks. There is a Matlab script node in LabVIEW that allows you to connect to the Matlab ActiveX server if you have Matlab installed. This allows you to run Matlab code and call .m scripts.

 

MathScript is distributed by National Instruments. It's a Matlab-like language. So, it looks like Matlab, but do not expect to be able to do everything you can do in Matlab with MathScript. There is also a MathScript node that you can use. It seems that's the one you want. Be aware: Starting with LabVIEW 2009, MathScript requires its own license.

 

 

In the end, why are you trying to do this with scripts? You can easily do what you want with G-code, as the previous post alludes to.

Message 3 of 5
(5,701 Views)

Because I'm writting a code to read a file from txt based on a matlab script (Because I've got already). So, I thought I could use some of the functions in a formula node. But what I can see is it's easier to treat arrays like above mentioned.  The reason I can't use matlab is because this code will become a test equipment and then it'd be very expesive one if I kept matlab and labview in the same machine. But anyway....tanks guys for you attention

 

Regrads

0 Kudos
Message 4 of 5
(5,674 Views)

Glad your ploblem is solved. Good luck!

Prashanth N
National Instruments
0 Kudos
Message 5 of 5
(5,660 Views)