LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Several problems with a simple replace array subset

Solved!
Go to solution

I'm new to LabVIEW and am trying to teach myself how to use it.  As you can imagine, I'm running into a few barriers.  The code I'm including embodies several of my problems.  If anyone can explain to me how to improve this code, I would be appreciative.

 

This code is a simplified version of a more complex code I'm trying to write.  In the simplified code, I have a control ("VALUE") which I'd like to record to different locations of my 5x3 array.  To do this, I tried to make a constant 5x3 array that I could overwrite with the control value.  The code isn't working as planned and here are my specific problems:

 

1. I can't seem to initialize the constant array (the one I plan to overwrite).  I can only initialize the first row.  Based on the help files, I thought I should be able to initialize it by clicking on the array boxes on the block diagram and entering in values.  But it doesn't seem to want to let me do that.  Not sure if there's a special way to initiate when more than 1 dimension is involved?

 

2. My slider controls are intended to establish where in the array to place the element.  But that isn't working either.  

 

3. I can't figure out how to properly terminate a code that has a while loop embedded in a while loop.  Someone had recommended using an event structure, but, as a beginner, I'm having difficulties figuring out how I would enact that.  I've tried playing with the latching/switching settings of the Stop button, but that hasn't worked out either. The problem seems to be that, if I'm inside the smaller while loop, the program doesn't see my Stop control.  Is there a way to wire it such that the Stop button works, regardless of if I'm inside the other while loop?  Alternatively, is there a way to accomplish what I want in the smaller while loop without using a while loop?  If I used an event structure, how would I set up an "event" to tell the program to store a new data point into the array?

 

Thanks.

 

Jessica

0 Kudos
Message 1 of 5
(2,817 Views)

Hi Jessica,

 

one starte tip:

Run your code with execution highlighted (the small light-buld on the block diagram).

This will show you that you reset the array on each iteration of the while loop!

 

I had no issues initializing the array on your BD, just double clicked one of the values and added some data:

 

You have wired the sliders into the 'Replace Array subset' primitive this replace one element of the initialized array. However the element must exist before the replace takes place. (notice in execution highlighting how what value of the slider is fed into the array.

 

If you resolved this you can go more advanced routes.

 

Let's see what you can do with event structures (they are your friend!)

 

Ton

 

 

 

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
Message 2 of 5
(2,810 Views)
Solution
Accepted by topic author jeisenstein

Jessica,

 

Also note that array indices in LabVIEW are zero based.  So the values for the row index can be 0, 1, or 2.  If you want your users to see 1, 2, and 3, then put a Decrement function between the slider terminals and the Replace Array Subset function.

 

 Lynn

Message 3 of 5
(2,803 Views)

Hi Jessica,

 

Here's a quick rewrite of your code, with comments telling you what I'm doing.  You could also use an event structure in your "capture" loop.  I didn't, but it would be a perfectly good (probably better) way to do it.

 

Hope this gives you a starting point.

 

d

 

Ah, I see that a couple of the guys beat me to it.  🙂

Message Edited by DianeS on 12-03-2009 04:06 PM
Message 4 of 5
(2,779 Views)

Thanks everyone!  All of these repsonses have provided me with the solution in some way.  I especially appreciate the re-write of the code.  I happened to have clicked on Lynn's response first for marking the solution because I didn't realize I only got one shot at it.  At any rate, I would have marked all three as solutions.

 

Jessica

0 Kudos
Message 5 of 5
(2,775 Views)