LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Change values elements in arrays

Hi everyone, I have tried over and over again to change the postion of array elemnts according to position of already existing array elements, but to no avail, I'll attach the pic of my VI so you could have a better look of what I am goinf for.

forum1.jpg

The initial value of the array is 1 2 2; 2 2 2, I want the array to hold the value of 2 1 2; 2 2 2 when I press right considering that it is previously been 1 2 2; 2 2 2, IF the array has the value of 2 1 2, 2 2 2, then I need the SAME array to hold the value of 2 2 1; 2 2 2 and so on.

 

If the VI helps I cld upload it 🙂

Thanks for all

T. A.
0 Kudos
Message 1 of 18
(16,159 Views)

Yes, upload the VI.

 

You have some misconceptions about how LabVIEW works and many thing make no sense. I don't quite understand your algorithm. Do you simply want to move the element containing "1" to the next flattened position? Something else?

 

You have a shift register that you never use during the loop. It serves no purpose here.

You don't show what's in the other cases so there is no way to tell what's happening. You also don't show the entire contents of the diagram constants.

Ideally you would place the indicator inside the loop and operate on the contents of the array in the shift register. No need for locals.

If all elements are "2" with the exception that only one is "1", you could use "array min/max" to get the position of the smallest element, i.e. the index location of the "1"

 

What should happen if the "1" is in the last position?

What are the possible array contents? Only 1 or 2?

If you are operating on integers, the array should be blue. Change the representation to I32, for example.

Index array is resizeable, so you only need one instance.

 

You might get a better idea what the program is doing of you run it in execution highlighting mode while watching the diagram. Try it! 🙂

0 Kudos
Message 2 of 18
(16,153 Views)

It's important to understand that variables don't exist in LabVIEW as they do in other languages. You should not consider the array indicator as a variable that you update. Instead, you should use wires to carry the data. You could use the data in the SR as your "variable" and pass it through the event structure to change it.

 

However, based on your description, it would probably be easiest if you hold the current "position" in a shift register and use the right/left buttons to increment and decrement it. Once you do that, you generate a new 1D array of 0s, and use the Replace Array Subset primitive to replace one element at the correct index. You can then use the Reshape Array primitive to turn it to a 2D array.

 

To learn more about LabVIEW, I suggest you try looking at some of these tutorials.


___________________
Try to take over the world!
Message 3 of 18
(16,153 Views)
okay i'll post something.
T. A.
0 Kudos
Message 4 of 18
(16,143 Views)

altenbach wrote:

 Do you simply want to move the element containing "1" to the next flattened position? Something else?


 

YES THIS IS THE THING!!

 

The thing is, it's not about 1 or 2, I want to use a True False in the real project, I just can't risk posting my work in front of hungry students.

 

I ultimately want to move a single true value around an x*x array using up/down left right buttons (here goes)

 

Message Edited by toniaz on 29-11-2009 11:23 AM
T. A.
0 Kudos
Message 5 of 18
(16,141 Views)

To all questions already asked by altenbach I would add these:

As you talk about "right" I suppose this 1-2 shift happens row based, right?

Do you need to do this for all rows in your 2D array?

 

I mean does array

12222

22122

21222

becomes

21222

22212

22122

after one "right" action?

 

If that is the case you need to scroll through all rows of your 2D array using a "For loop" and perform

"Search 1D array" to find 1's in the actual row

"Replace array subset" to replace the found 1 by a 2 and the next element (most likely a 2) by 1

If one row can contain more than one 1's to replace you need a  "While loop" to find all 1's of one row.

 

Finally you get something like this

SNAG-010.jpg

Please note that this code doesn't take care of "last coloumn" problem already mentioned by altanbech 😞

Message 6 of 18
(16,138 Views)

toniaz wrote:

The thing is, it's not about 1 or 2, I want to use a True False in the real project, I just can't risk posting my work in front of hungry students.


Well, algorithmically there is no diffference between numbers and booleans, so things won't be that secret. Here's one way to do it, but there are many other, equally easy ways. Also be aware that your teacher at AUB probably reads these forums, so be creative and ensure two things: completely understand every aspect of the code you're using. Don't be afraid to personalize and modify it.

 

I assuming that only one element is different. Things get a bit more complicated if you would need to e.g. swap adjacent values.

 

 

None of this is really needed to play tic-tac-toe, so maybe you're just wasting your time. 😄

BTW, the above image is a labview snippet. Drag it to an empty LabVIEW 2009 diagram and it will turn into runnable code. 🙂
Message Edited by altenbach on 11-29-2009 01:35 AM
Message 7 of 18
(16,138 Views)

1st of all, are we allowed to use a wt* in this forum? 😄

second of all, there is a tic tac toe fiasco, the stipulated conditions for the game are very stupid (with respect to any monitoring professor). It is required to build a 3*3 boolean array (LED array with a single lit LED). We need to move the LED using 4 buttons: up down left and right, we must connect the array to a string array, once the OK button (a 4th button is pressed) the cell in the string array will indicate X or O. Very interesting, aye? more over, we should switch turns automatically, so the main purpose of this very post is to know how to move the lit LED within the LED array, if the vi I wrote is needless, please inform me 😞

T. A.
0 Kudos
Message 8 of 18
(16,133 Views)

Alain S wrote:

Do you need to do this for all rows in your 2D array?

 

I mean does array

12222

22122

21222

becomes

21222

22212

22122

after one "right" action?


 

Not quite, but 1st since our cover is blown, i will answer you specifically, what I want to do when I press right is:

 

TFF

FFF

FFF

BCOMES

FTF

FFF

FFF

 

and

FFF

FFT

FFF

BECOMES

FFF

TFF

FFF

for instance, its just the T value I am interested in

 

T. A.
0 Kudos
Message 9 of 18
(16,131 Views)

Ok is there a way to delete this thread? (6) I think I figured altenbach's diagram, I just need to turn it to boolean 😄

 

altenbach for presient 2010 😄

T. A.
0 Kudos
Message 10 of 18
(16,126 Views)