LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

for loop

Highlighted

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
(1,668 Views)
Highlighted

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
0 Kudos
Message 2 of 10
(1,661 Views)
Highlighted

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...

-------------------------------------------------------------------
Unfortunately, most readers of this Forum, including some real Experts, have not mastered the skill of being able to read the code that Posters fail to post. If we cannot see "what you did wrong", we are unable to tell you how to fix it. (Bob Schor 28 August 2018)
0 Kudos
Message 3 of 10
(1,655 Views)
Highlighted

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
(1,641 Views)
Highlighted

@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
Message 5 of 10
(1,633 Views)
Highlighted

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
(1,604 Views)
Highlighted

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

0 Kudos
Message 7 of 10
(1,598 Views)
Highlighted

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

GCentral
Message 8 of 10
(1,592 Views)
Highlighted

@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
0 Kudos
Message 9 of 10
(1,575 Views)
Highlighted

@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! ADDQ VIPM Now on GitHub
"Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
Certified-LabVIEW-Developer
0 Kudos
Message 10 of 10
(1,529 Views)