LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with an array

Solved!
Go to solution

EduU,

 

Out of interest, how big will this array ever get. The reason i ask is that if you are talking about an array that could potentially get large then using 'Build Array' Functions to create your 2 arrays should be avoided. Instead you should try to calculate the size of the 2 arrays, use 'Initialise Array, and then use 'Replace array subset' in your loop:

 

Negative positive array 2.png

 

Just another option to think about, especially if you are going to be using large arrays.

 

Rgs,

 

Lucither.

------------------------------------------------------------------------------------------------------
"Everything should be made as simple as possible but no simpler"
0 Kudos
Message 11 of 20
(876 Views)

Here is the 8.2 version

 

Rgs,

 

Lucither

------------------------------------------------------------------------------------------------------
"Everything should be made as simple as possible but no simpler"
0 Kudos
Message 12 of 20
(874 Views)

VI saved in 8.6...

0 Kudos
Message 13 of 20
(863 Views)

Lucither, this array have 7353 numbers on that, you think is too much!?

Thanks for the new example, I will try it and see if I have something different.

0 Kudos
Message 14 of 20
(852 Views)

EduU,

 

Thats simply answered by benchmarking:

 

My Snippet.png

 

Other snippet.png

 

For an array of your size i dont beleive the difference will be significant. The above benchmarks are:

 

Mine: 2ms

Other: 14ms

 

The difference would become greater though as the array gets larger.

 

Another point that was noted when comparing the 2 array outputs. The arrays compiled by the bottom array are in reverse order to how they where initially made. Dont know if this matters to you but if it does you could either reverse the array's or simply change the 'Build Array' input so you are inputting the new value to the bottom (Currently top).

 

For large arrays (and personally i always do it where possible) it is far more efficient to use 'Replace Array subset', using build array is constantly changing the size of the array which has a lot of overheads and hence takes longer.

 

Rgs,

 

Lucither.

------------------------------------------------------------------------------------------------------
"Everything should be made as simple as possible but no simpler"
0 Kudos
Message 15 of 20
(844 Views)

EduU,

 

Just to highlight the problems associated with 'Build Array' go to Here. You will see that just by removing 'Build Array' and optimising the original OP's code the speed was improved x1.5Million times! Under tests the original code would execute in 2.5 hours whereas the optimised code ran an average <10ms!

 

Build Array is evil!Smiley Very Happy

 

Rgs,

 

Lucither.

------------------------------------------------------------------------------------------------------
"Everything should be made as simple as possible but no simpler"
0 Kudos
Message 16 of 20
(840 Views)

Lucither,

 

Thanks for the explanation!

Well the array isn't my priorioty, but is always good make the things better, one thing i'm having problem to implement your solution is because, this program is develop in LabVIEW 7.1 and in 7.1 we don't have the conditional terminal at for loop, I don't know if this is the problem, but because of that I'm getting only 1 positive number.

 

 

Is because of that!?

 

Thanks

0 Kudos
Message 17 of 20
(839 Views)

Yep, that will be the reason. Here it is without the for loop:

 

Negative positive while loop.png

 

Rgs,

 

Lucither.

------------------------------------------------------------------------------------------------------
"Everything should be made as simple as possible but no simpler"
0 Kudos
Message 18 of 20
(831 Views)

Lucither, Thanks for the new VI without conditional terminal!

 

and I saw the page you linked, oh my god 1.555million times for sure is a lot of time haha

I will put this idea in my program now, thanks

0 Kudos
Message 19 of 20
(824 Views)

EduU,

 

Just to quickly highlight the problem. If we repeat the above benchmarks but with an array of 1 Million the results are:

 

Mine: 408ms

Other: 608704ms or 10 minutes and 8 seconds!

 

I know that 1 Million is a large number but this is just to show how the speed difference becomes a lot larger as the array becomes larger.

 

Rgs,

 

Lucither.

------------------------------------------------------------------------------------------------------
"Everything should be made as simple as possible but no simpler"
0 Kudos
Message 20 of 20
(823 Views)