LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Fill array with formula nodewith one line of code

Solved!
Go to solution

Hi,

 

This is my first post to NI community, maybe this question has been asked 1000 times but I could'nt find any answer.

 

Before using LabView I used Matlab a lot. I kinda find it too complicated for no reason sometimes in labview to work with arrays.

 

I inherited and I'm trying to do some clean up. what this does is extractr the 2 and 3 position and creates a new array with it and another oner with the others elements of the first array. I find it gets confusing because you have to count on the array box the position of the output and I don't wat to work that way.

Capture.PNG

I replaced this with a formula node. Here's the code

The starting array is FP, the 6 elements array is mdot and the 2 elements array is press 

 

float64 mdot[6], press[2];


mdot[0]=FP[0];mdot[1]=FP[1];      
mdot[2]=FP[4];mdot[3]=FP[5];
mdot[4]=FP[6];mdot[5]=FP[7];

 

press[0]=FP[2];press[1]=FP[3];

 

Now I want to know if it is possible to do like I would in matlab or C, where you can create an array with one line of code. What would be the syntax in formula node to do something like:

mdot[6]=[FP[0],FP[1],FP[4],FP[5],FP[6],FP[7]];

press[2]=[FP[2],FP[3]];

 

Thanks,

0 Kudos
Message 1 of 16
(3,890 Views)
Solution
Accepted by topic author BassBijj

Use Delete From Array.  You can supply an index and length of elements to remove.  One of the outputs will be the original array with the subset deleted and the other output is the deleted subset.  1 NODE!

 

EDIT: Created a snippet right after my previous post.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 16
(3,881 Views)
Solution
Accepted by topic author BassBijj

Hi Bassam,

 

that's how your one-liner looks in LabVIEW:

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 16
(3,879 Views)

Thanks for the answer I will use this before my calculation in the formula node, but lets say I REALLLLY want to code it, is what I'm asking possible ?

0 Kudos
Message 4 of 16
(3,876 Views)

@Bassam_Bijjani wrote:

Thanks for the answer I will use this before my calculation in the formula node, but lets say I REALLLLY want to code it, is what I'm asking possible ?


I'm not sure what you are asking.  We just showed you how to code it for real.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 16
(3,867 Views)

Hi Bassam,

 

why do you want to "clean up" LabVIEW code by using a rather slow formula node - when pure and simple G code is available?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 16
(3,866 Views)

In this case the two value to extract where 2 and 3 position but if they were 2 and 5 I would have needed to use 2 delete from array..and so on depending on the first array...

 

I find it more clearer to use a formula node because you don't need to count the very small wire output you just see it in the formula node code. Now if formula node are slower I wasn't aware of that..how much slower are they really ? I understand this way (formula) might not be the most efficient..but is it this bad or you just prefer the graphical solution ?

 

I knew the solution by using the delete from array bloc...but I don't know how to code it in a formula node in one single line like I specify in my first post.

 

Is it possible or not ? What is the syntax if it is possible ?

0 Kudos
Message 7 of 16
(3,844 Views)

In this case the two value to extract where 2 and 3 position but if they were 2 and 5 I would have needed to use 2 delete from array..and so on depending on the first array...

 

I find it more clearer to use a formula node because you don't need to count the very small wire output you just see it in the formula node code. Now if formula node are slower I wasn't aware of that..how much slower are they really ? I understand this way (formula) might not be the most efficient..but is it this bad or you just prefer the graphical solution ?

 

I knew the solution by using the delete from array bloc...but I don't know how to code it in a formula node in one single line like I specify in my first post.

 

Is it possible or not ? What is the syntax if it is possible ?

0 Kudos
Message 8 of 16
(3,843 Views)

Hi Bassam,

 

when the number and index of those elements are variable you would use a loop and employ autoindexing…

 

You don't need to count any IndexArray outputs for this task:

check.png

 

you just prefer the graphical solution ?

LabVIEW is a graphical programming environment. Why do you even choose LabVIEW when you don't want to use that language?

 

but I don't know how to code it in a formula node in one single line like I specify in my first post.

The formula node uses a C-like syntax. The help explains the accepted commands. Why don't you try this on your own?

When there are syntax errors the compiler will point you on them…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 9 of 16
(3,821 Views)

Thanks for the quite elegent graphical solution,

 

Why do you even use labview...?

I could simply return the question ..Why would labview include formula node since it is a grapical programming environement ? If its not slower and gets the job done why wouldn't I use it ?

 

Personnaly I think it is  more simple to use a formula node where you create and X array by filling it with any elements of an Y array...

X=[first element of Y, third element of Y, sixth element of Y] for example..

 

I wouldn't have been able to produce the solution you showed me on my on..it's quite unintuitive for me..and I still don't get why you reverse before the loop and after...is it to start splitting the array from the bottom ?

 

it is the only time I wanted to use the formula node and I've tried to look in the help before asking question. I was sure it had something to do with synthax, something that would have been easier for some others since I dont really know C either..I've only used Matlab in the past and syntax is way different..

0 Kudos
Message 10 of 16
(3,801 Views)