LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

for loop array issue

Solved!
Go to solution

Even if I read in the file outside of the for loop. I was not able to find a way for labview to iterate by two.

 

something like this;

 

for(int 1=0; i<5000; i+=2)

0 Kudos
Message 21 of 34
(1,844 Views)

Do you want to say you wanted to access the elements like this

for loop.png

Message 22 of 34
(1,837 Views)

Dear Neos,

 

                      First Time it will access 2nd element not 0th element, 2nd time it will 3rd and so on. hence better use shift register

--------------------------------------------------------------------------------------------------------
Kudos are always welcome if you got solution to some extent.

I need my difficulties because they are necessary to enjoy my success.
--Ranjeet
0 Kudos
Message 23 of 34
(1,834 Views)

i+2.png  

 

Is this OK?

--------------------------------------------------------------------------------------------------------
Kudos are always welcome if you got solution to some extent.

I need my difficulties because they are necessary to enjoy my success.
--Ranjeet
Message 24 of 34
(1,832 Views)

Ranjeet_Singh wrote:

 

Dear Neos,

 

                      First Time it will access 2nd element not 0th element, 2nd time it will 3rd and so on. hence better use shift register

 


Please pay attention to the original discussion. User has 1D array from which he wants to use 2 elements at a time ( we still don't know How? ) and feed them to a subvi.

My thought from his iterate by two was , he wants to access 0th and 2nd elements, 1st and 3rd elements .........( May be I am wrong here )

 

You obviosly didnt see it correct.

because your attached image shows as if we want an element from an array like every iteration  row no. are changing and column nos. are shifting by two.

 

Way shifted from target.

 

 

0 Kudos
Message 25 of 34
(1,829 Views)

@kulsman wrote:

Even if I read in the file outside of the for loop. I was not able to find a way for labview to iterate by two.

 

something like this;

 

for(int 1=0; i<5000; i+=2)


You please pay attention. 

--------------------------------------------------------------------------------------------------------
Kudos are always welcome if you got solution to some extent.

I need my difficulties because they are necessary to enjoy my success.
--Ranjeet
0 Kudos
Message 26 of 34
(1,823 Views)
Solution
Accepted by topic author kulsman

The solution by NEOS or Ranj are not really what you want. It seems you want "for(int i=0; i<5000; i+=2)" on the first element and "for(int i=1; i<5000; i+=2)" on the second element. Here's how you would do that.

 

Note that it is i=0, not 1=0, which would not make any sense.

 

 

 

Note that N needs to be wired  at half the input array size (not shown). In the code I had attached earlier, I reshape the file into two columns, making everything simpler while getting two adjacent elements automatically. Have you looked at it?

 

It would seem more reasonable to read the file as U16 and splin inside the loop.

 

 

 

Message 27 of 34
(1,816 Views)

No No Christian........

In my post i wasn't talking about solution 

Don't get me wrong for that 

I was actually asking what he wants, that i have mentioned n my post also saying i may be wrong 

 

 

your solution infact as given me something if i would have done that probabaly ( i am sure ) it must have been rubed.

0 Kudos
Message 28 of 34
(1,808 Views)

I want to personally thank altenbach, Neos, and Ranjeet_Singh for assisting me on this problem.

I have learned that it is a bad idea to read in file every iteration of the for loop. Also differences between N and I in the for loop.

 

I have implmented something similar to what altenbach proposed.

0 Kudos
Message 29 of 34
(1,790 Views)

@kulsman wrote:


I have learned that it is a bad idea to read in file every iteration of the for loop. Also differences between N and I in the for loop.

I have implmented something similar to what altenbach proposed.

 


You are still doing things way too complicated.

 

  • As I already said, "Index array" is resizeable to get more than one element at once, and if you wire the upper index input, the lower input is assumed to be one higher. There is no need to wire the second index array or the explicit "+1" math.
  • I would still say that a reshaping would be simpler, because it allows autoindexing and you don't even need to wire N or test for termination. (See the example I have attached earlier).
  • Using the conditional terminal is just silly. You can hide the conditional terminal and calculate the correct number of iterations before the loop even starts. It's just the size of the input array divided by two! Wire that the the N input (You don't show what value you wire there, that's why images are pretty useless for debugging. Attach the actual VI instead.)
0 Kudos
Message 30 of 34
(1,779 Views)