LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help with complicated 2d array build

Solved!
Go to solution

Hello,

 

Just a short introduce: I'm new to labview programming, this is my first post here on forum. This forum has been very useful in my start with learning labview programming. Currently just have an issue that i'm not able to fix, some ideas or help would be very welcome. Smiley Wink

 

The measurement setup: I'm making a program for a measurement setup with a sensor mounted on two axis, x and y. By moving the axis I can measure a square field of points. For technical reasons measurements always start in the bottom left side of the field, then I measure all the points above it by moving the sensor along the Y-axis. Then I move the sensor one step to the right on the X- axis and read all the points on the Y-axis again and create my field of measuring points by this. Reading the sensor data and doing some basic stuff like calculations and displaying in charts and writing to excel is not a problem.

 

Now I have a two questions: (obviously after trying hard Smiley Frustrated)

- How do I fill a 2d array starting at the bottom left side and ending in the top right side. (Filling columns first as described)

- Secondly, I want to fill every cell of that array only when I a click on a button on the front panel, but how?

 

So in the end I get something like this: I click on the button, then measurement starts, reads the sensor value into bottom left cell of array, then program 'jumps' to cell above it. Then the whole thing over again, I click the button, read the value and so on. Well I hope you guys get the idea...

 

I guess I have to program the 'array-fill-code' in a case structure that becomes true when the button is clicked. And I think that I have to use the 'build array' function or the 'replace array subset' function. But how?

 

Any help, ideas, inspiration or example vi's are welcome!

With best regards,

WHW

0 Kudos
Message 1 of 8
(3,840 Views)

Hi WHW,

 

I guess I have to program the 'array-fill-code' in a case structure that becomes true when the button is clicked.

You're right.

 

And I think that I have to use the 'build array' function or the 'replace array subset' function. But how?

You need to initialize the array before the measurement loop. In the loop you use ReplaceArraySubset to put the measurement in the array element you like to…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 8
(3,820 Views)

Hi GerdW,

 

Thanks for the quick reply.

I'm indeed on the right way then. I understand that I have to initialize the array before measurement loop as well. Forgot to tell that.

 

Maybe I can specify the question a bit: I have mainly troubles with telling the ReplaceArraySubset where to write in the array. I have two variables which tell the amount of points on X and Y axis. They need to be checked, then the index of where to write in the array need to be determined and told to the ReplaceArraySubset. As well that index needs to be remembered till the next iteration when you click the button again. Something you'd do with a shift register in a while loop, but this isnt a while loop but a case... I dont know how to do it.

 

I have included a vi where you can see how far I came.

I hope someone can help!


Thanks in advance!

Regards,

WHW

 

0 Kudos
Message 3 of 8
(3,800 Views)

Hi WHW,

 

a couple of things:

 

- I personally would use enums for the "Measurement points X/Y". That way you avoid having to convert from string to numeric

- I don't know why you use a local variable, since I don't know what your program looks like, but I advice you to be careful with the locals.

 

As for your problem:

Why is it not a while loop? My first impulse was to use a while loop and determine the position in the array by Quotient/Remainder dividing the index. Depending on where you want your values to go you need to define your logic.

 

If you absolutely can't have a while loop, you could save the position in a feedback node.



Remember Cunningham's Law
Message 4 of 8
(3,785 Views)

Hi PeterFoerster,

 

Thanks for reply. 

I'll keep in mind your two things you mentioned. That is helpful.

 

Regarding your question: The idea is that I fill the array when a button is clicked. Thats where the case structure comes in, the case only needs to be executed when the button is clicked.

 

I am able to implement the write in array with two for loops, one to fill x and one to fill y axis, no problem at all. See picture below. But with that implementation it starts with filling in the top left corner, where it needs to be the bottom left corner, and next to that i just want to save ONE measurement sample to a place in the array by clicking a button.

 

for loops.bmp

Not sure how you mean to implement quotient/remainder dividing the index?

 

Can anyone help?

Thanks a lot!

0 Kudos
Message 5 of 8
(3,773 Views)
Solution
Accepted by topic author HEWI

Hi Hewi,

 

But with that implementation it starts with filling in the top left corner, where it needs to be the bottom left corner, and next to that i just want to save ONE measurement sample to a place in the array by clicking a button.

You need to program this behaviour. Create your own logic to count/calc the array indizes: use a while loop with 3 shift registers (array data, x index, y index). Inside the loop comes your case structure with abutton connected to the selector. Inside the case you ReplaceArraySubset with the new measurement values and your logic to update the indices…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 8
(3,755 Views)

As soon as we have an index it becomes much easier. The solution with two for loops is best, but if you had only one loop you would need quotient/remainder. You can make the function start in the low left column by wiring (N-i-1) to the column index instead of i). And you can use event structures to only write to the table when you push a button. For small programs this is OK...

If you want to use a case structure, just use shift registers or feedback nodes to store the current position. Then you would have to switch the inner for loop to a while loop, though.



Remember Cunningham's Law
Message 7 of 8
(3,748 Views)

Hi GerdW,

 

Your solution with the case structure inside the while works! Smiley Very Happy

 

Thanks a lot!

WHW

0 Kudos
Message 8 of 8
(3,714 Views)