LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

for loop

Hi all,

 

I would be grateful if someone can help me to solve this issue,

 

I have a FOR loop, this FOR loop gives me a sequence of numbers from zero to1 million (1000000) as mentioned in the attached file. the probelm is this for loop makes my code is too slow when I run the code. So is there anyone can help me to replace this for loop with something more efficient and gives me the same results. thanks in advance

 

Regards

0 Kudos
Message 1 of 10
(3,442 Views)

What else do you have in your code?  I would not expect this, as shown, to slow down your code.  It should just compile down to a constant.


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 2 of 10
(3,435 Views)

You don't then the fact that you are creating an array with a million elements has anything to do with it do you?

 

What exactly are you trying to do?

 

Actually I just ran that code and it takes less than one second to make that 1,000,000 element array, so I guess that is not it...

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 3 of 10
(3,429 Views)

the 1 million is just the number of smaples that I am using to represent the X-axis i the XY graph, so I was using this way to get that. but long time ago I was suffering from the code is being so slow and today by the chance I discovered that when I delet the for loop I got so fast code but offcourse with wrong results.

 

SO that's why I am trying to find out the alternative way to get ride of the FOR loop in my code.

0 Kudos
Message 4 of 10
(3,415 Views)

@Al-rawachy wrote:

the 1 million is just the number of smaples that I am using to represent the X-axis i the XY graph, so I was using this way to get that. but long time ago I was suffering from the code is being so slow and today by the chance I discovered that when I delet the for loop I got so fast code but offcourse with wrong results.


Why not just use a normal graph instead?  Then you do not have to supply the X-axis and it will just be a sample count for the x-axis.


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 5 of 10
(3,407 Views)

Under "Normal" graph crossrulz means waveform graph.

With default options, if you just wire Y array to its terminal, X-axis will be automatically a duplicate of your XY-graph (start = 0, step = 1).

Message 6 of 10
(3,378 Views)

I am using XY graph becasue I have to plot two different things on th same plot

0 Kudos
Message 7 of 10
(3,372 Views)

We would really need to see more of your code to try to give suggestions. I ran a quick test with the code below and the average run time was around .006 seconds or so.

 

FSTime.png

 

As someone mentioned above, the for loop should be constant folded if you have debugging disabled, although it didn't indicate that to me when I tried. Either way, .006 seconds would normally be unnoticable, are you by chance doing this array creation in a loop very quickly?

Matt J | National Instruments | CLA
Message 8 of 10
(3,366 Views)

@Al-rawachy wrote:

I am using XY graph becasue I have to plot two different things on th same plot


And what are these two different things?  Does the second plot need the XY?


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 9 of 10
(3,349 Views)

@Al-rawachy wrote:

I am using XY graph becasue I have to plot two different things on th same plot


You can plot 2 waveforms in a waveform graph. If the other is of another sampling frequency it can be padded. Only if the 2nd is sporadic a XY graph is warrented.

Still, it shouldn't be that for loop that's the culprit.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 10 of 10
(3,303 Views)