cancel
Showing results for 
Search instead for 
Did you mean: 

inserting single element into 2d array

Harry2020
Member

Re: inserting single element into 2d array

Message contains an image

Hola, estoy intentando algo similar, mediante un replace array subset pero en un arreglo boleano. La idea es que funcione como un disparo, le doy la coordenada, disparo y se enciende un led, pero tengo un problema quiero que ese led permanezca encendido hasta el siguiente disparo, si disparo una a una todas las casillas debería mantenerse el estado anterior, les adjunto foto del código para el programa, arriba tengo la entrada de un arreglo boleano. Agradezco sus sugerencias y ayudaCaptura de Pantalla 2020-05-08 a la(s) 12.15.06 a. m..png

altenbach
Knight of NI

Re: inserting single element into 2d array

Keep the 2D array in a shift register anchored on the while loop.

 

(Also, the terminal of the OK button belongs inside its event case. You know the number of iterations before the loop starts, so it should be a FOR loop. Of course it would be better to have a state machine instead of stopping the VI at the end, so a while loop is better for that. Where is the terminal belonging to the local variable? Feel free tho attach the VI. we cannot efficiently debug pictures.)

altenbach
Knight of NI

Re: inserting single element into 2d array

Message contains an image

See if this helps:

 

altenbach_0-1588920602149.png

 

paul_cardinale
Trusted Enthusiast

Re: inserting single element into 2d array

Message contains an image Message contains an attachment

@AntoineP wrote:

You cannot replace an element of an array if that element does not exist.

 

 For exemple trying to replace element on the 4th row and 1st column of a 3x3 array will result in the same array as output

 

 

     ====>>>>    
Message Edited by AntoineP on 10-09-2008 02:22 PM

That's why I created this.

"If you weren't supposed to push it, it wouldn't be a button."
Frozen
Active Participant

Re: inserting single element into 2d array

Thanks Paul. I am going to add that to my secret stash of super-usable vis!

---------------------------------------------
Former Certified LabVIEW Developer (CLD)
altenbach
Knight of NI

Re: inserting single element into 2d array

Message contains an image Message contains an attachment

@paul_cardinale wrote:
That's why I created this.

I am sure it can be simplified dramatically.

(It could even be expanded to work with arrays of any dimensions. Not shown)

 

altenbach_0-1588957253905.png

 

 

(Sorry, I attached wrong code earlier. Disregard that. Please verify correct operation)

 

 

 

 

Harry2020
Member

Re: inserting single element into 2d array

Gracias por la respuesta, bueno, estoy esforzándome por entender muchos conceptos, eso se trata de un juego de batalla naval, inicialmente estoy generando los barcos de 5,4 y 3 bits aleatoriamente, sin que se crucen, con algunos problemas cuando cambian de sentido, ese arreglo final quiero compararlo con uno que genere el usuario con esos disparos, te adjunto mi programa y agradezco todas las sugerencias, tengo mucho por aprender. Gracias, por ahora me sale un aviso que el tipo de archivo (.vi) no se admite, no puedo adjuntártelo

altenbach
Knight of NI

Re: inserting single element into 2d array

You did not attach anything yet.

paul_cardinale
Trusted Enthusiast

Re: inserting single element into 2d array

Message contains an image Message contains an attachment

@altenbach wrote:

@paul_cardinale wrote:
That's why I created this.

I am sure it can be simplified dramatically.

(It could even be expanded to work with arrays of any dimensions. Not shown)

 

altenbach_0-1588957253905.png

 

 

(Sorry, I attached wrong code earlier. Disregard that. Please verify correct operation)

 

 

 

 


Here's the whole set, with your improvements.

"If you weren't supposed to push it, it wouldn't be a button."

Re: inserting single element into 2d array

You technically can't as labview enforces that the other columns be of the same size so you have to put your value into that column and pad the rest with zeros. You can then replace those zeros later if you keep track of where they are with a shift register or array.