LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

building an array based on while loop iterations

I want to build a 4x18000 matrix like the following:
(x,y,z,m); where x ranges from -30 to 30, y ranges from -30 to 30 and z ranges from -40 to 40.
For each point (x,y,z) I want to be able to input the value of m into the matrix on every 64th iteration of a while loop.  (This value is theoretically being read in from the USB, but how to get that to work is a different question).  We will just assume I have it on hand for now. 
does anyone have any ideas how to do this?
0 Kudos
Message 1 of 9
(3,081 Views)

In general, it's better to use a for loop when building arrays because the while loop requires dynamic memory allocation. However, if you know that your array will always be of that size, you can initialize it before entering the loop and use shift registers coupled with Replace Array Subset in a case structure to replace the elements you want.

It's unclear where your problem is, but if it is in finding out that 64 iterations have passed, you can do that by something as simple as having a running counter (with a shift register) which will increment by one with each iteration. Another option is to add 1 to the iteration counter and feed the result (together with 64) into the Quotient & Remainder function. Whenever the remainder is 0 you're on a multiple of 64 (the one is added to avoid getting 0 on the first iteration). If this doesn't help you, explain exactly what your problem is.


___________________
Try to take over the world!
0 Kudos
Message 2 of 9
(3,074 Views)
Hi,
 
I have attached a VI that might be what you are looking for.
 
Hope this helps.
 
- Gurdas
Gurdas Sandhu, Ph.D.
ORISE Research Fellow at US EPA
0 Kudos
Message 3 of 9
(3,069 Views)
  1. Could you explain what value m should have if the iteration is not a multiple of 64?
  2. Should x,y,z form a regular 3D grid, and if not, where do the x,y,z values come from?

If you want to generate a regular 3D lattice, you could do something like in the attached example. Of course you need ot change the indexing order according to your requirements.

0 Kudos
Message 4 of 9
(3,061 Views)
Okay, using the VI's that you guys gave, I modded it to do almost what I want.  My new VI is attached.  However I have a problem.
Problem:
                Write now the X columb in the array counts up from 0 to 29 and then counts down from 0 to -29.  I want it to count up from 0 to 30 and then down to 0 again.  I can't seem to get it to do this.
               
0 Kudos
Message 5 of 9
(3,039 Views)

What are you actually trying to do? Please just describe how you want to fill the elements of the 2D array and one of us will show you how with a few mouse strokes.

Your VI is way too confusing and overly complex. You are overwriting each column 64 times in a row before proceeding to the next column. This is a lot of unecessary work! Why?!

Message Edited by altenbach on 03-29-2006 09:16 AM

0 Kudos
Message 6 of 9
(3,024 Views)

I want the X value of the array to fill in counting up from 0 to 30 and then back down to 0 where a value gets filled in to the X part of the array every 64th cycle of the loop. 

Then I want the Y value of the array to count up from 0 to 29 and then start over at 0 again and count again.  I want the Y value to increment every time the X value reaches 0 or 30 (except the first 0).

Then I want the Z value of the array to count up from 0 to 79.  I want it to increment every time the Y value is 0 (except the very first). 

Does this make sence?  That is what I was trying to do in my code.

0 Kudos
Message 7 of 9
(3,008 Views)


@musser wrote:

Then I want the Z value of the array to count up from 0 to 79.  I want it to increment every time the Y value is 0 (except the very first).


Well, this is not entirely clear...

  1. If you want to increment Z every time they Y values is 0, it will count much higher than 79, because Y=0 for many consecutive values.
  2. If you want to increment Z only if ((X=0 OR X=30) AND Y=0), you'll only count to about 39, not to 79.

Attached is a simple example that more or less implements my interpretation (point 2 above) of your requirements (LabVIEW 8.0).  To save memory, I do everything as I32 (You could even do it as U8!). Maybe you can modify it for your needs. 🙂

For easy inspection of the resulting array, I display it also on a graph.

0 Kudos
Message 8 of 9
(2,995 Views)

I ment 39, 79 was a typo.  Thanks for the help, this is perfect

 

0 Kudos
Message 9 of 9
(2,972 Views)