LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Element at every 3rd Iteration of a 2D array

Greetings!

I'm very new to LabVIEW software as I've spent around 20 days on it till now. Can someone please help me showing how to extract the element at every 3rd iteration in a 2D array. The rows and coloumns of the array are to be user defined.

 

I'm reminding of the fact he I don't want to extract the 3rd element of each row or coloumn, I want element at every 3rd iteration, and also the count should continue onto next row. My mentor told me to use Shift Registor but I don't know how to implement it here. Thank you in anticipation.

0 Kudos
Message 1 of 11
(3,440 Views)

Hi Adi,

 

you need to provide more information - or more clear information…

 

how to extract the element at every 3rd iteration in a 2D array.

Which element do you want to 2extract" aka index?

What is an "iteration in a 2D array"?

Why do you only need an element every 3rd iteration (of a loop probably…)?

 

The rows and coloumns of the array are to be user defined.

So you don't know the array size at edit time? Thanks to that ArraySize function…

 

I don't want to extract the 3rd element of each row or coloumn, I want element at every 3rd iteration,

Again: which element do you want to index?

Please provide a clear example, preferably in a VI with some default values!

 

and also the count should continue onto next row.

Which "count" are you talking about?

Why should it "continue to next row"? Why not continue to next column?

 

My mentor told me to use Shift Registor but I don't know how to implement it here.

So I guess this is homework intended to let you learn LabVIEW.

Why don't you ask your mentor/teacher?

(You may ask here, but please don't expect ready-to-use solutions.)

To learn about shift registers you should go through all those free beginner resources offered by NI on their website!

Best regards,
GerdW


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

Thank you for the response and pointing out my mistakes.

I'll try to elaborate it a bit here.

Capture2.PNG

 

Here I create a 2D array of random numbers with 5 rows and 7 coloumns (suppose).

The output I'm looking for is a 1D array of elements [8, 3, 3, 10, 8, 5........] and so on. I hope you understood the meaning of element at every 3rd position of iteration.

 

0 Kudos
Message 3 of 11
(3,409 Views)

ReshapeArray from 2D to 1D, then Decimate1DArray into 3 parts.

Ready…

 

I hope you understood the meaning of element at every 3rd position of iteration.

So you count all elements row-wise…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 11
(3,405 Views)

Thank you so much.

That's exactly the kind of array I needed as output. But can you show me how to do that using a loop and shift registors.

I'd be grateful!

0 Kudos
Message 5 of 11
(3,372 Views)

Hi adi,

 

I already gave you a solution. Please do your homework on your own!

 

(I have a solution in my mind using some integer arithmetic with quotient & remainder to index the correct elements...)

Best regards,
GerdW


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

eit.png

 

(Note: you are misusing the word "iteration".)

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 7 of 11
(3,361 Views)

For a loop based method, you should Reshape the array as already shown, then you can read the method I gave here yesterday: Saving data after specific increments. That link had a slightly different goal, but still wanted every third element from a 1D array. Hopefully it's obvious which parts you should delete if you're not writing to file 🙂

 

The snippet is below, but the link above has far more detailed explanation of why I used those functions. You'd want to change the input to the top of the Quotient and Remainder function, since this example was looking for multiples of 3. You want 3rd elements, so use a value that increases by one each iteration. Hint: You don't need a shift register - it's already on the diagram 😉

mod3.png


GCentral
0 Kudos
Message 8 of 11
(3,352 Views)

@cbutcher wrote:

For a loop based method, you should Reshape the array as already shown, then you can read the method I gave here yesterday: Saving data after specific increments. That link had a slightly different goal, but still wanted every third element from a 1D array. Hopefully it's obvious which parts you should delete if you're not writing to file 🙂

 

The snippet is below, but the link above has far more detailed explanation of why I used those functions. You'd want to change the input to the top of the Quotient and Remainder function, since this example was looking for multiples of 3. You want 3rd elements, so use a value that increases by one each iteration. Hint: You don't need a shift register - it's already on the diagram 😉

mod3.png


Missed the specs there cb

Capture Start.PNG


"Should be" isn't "Is" -Jay
0 Kudos
Message 9 of 11
(3,348 Views)

Jeff·Þ·Bohrer wrote:

 

Missed the specs there cb

Capture Start.PNG


I did? Below is my modified snippet, doing the actual task here - I had thought people were avoiding "ready-to-use solutions" at GerdW's suggestion, but it seems there are several to choose from now.

3rdElement.png

 

Nice reshape though... very slim. I wonder if it's slower though - does the Reshape Array just alter dimension sizing, whilst your for loop copies into a new array? I don't know...


GCentral
Message 10 of 11
(3,341 Views)