LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Beginner Question: Extracting Array Values From Nested Loops

Ok so I've just started using Labview and I need to modify an existing VI for an experiments setup, setting values for temperature and magnetic field.

 

Below are the front panel and block diagram.


When you enter the values on the front panel it generates an array beginning at the start value and ending on the end value, quite straightforward so far.

 

So I want to modify the VI to do two things:

 

1. Make it so you can't repeat the first value from the previous last value. What I mean by this is lets say for the temperature input data, you set the values to be:

 

Start End Steps

100 90     5

90   80     5

 

this will generate two arrrays in the cluster of:

 

100

95

90

 

90

85

80

 

But I don't want it to have two values of 90, So if the end of one and the start of the next are the same I want to add the value of steps to the second one so it would become 85 and not 90.

 

2. This is the more important one, on the front panel there are buttons for "Temperature Const - Magnetic Field" and "Magnetic Field Const - Temperature". When either these button are pressed I want it to generate two arrays (or 1, 2d array) where it cycles keeps one variable the same and cycles through the other.

 

Example if you set "Temperature Const - Magnetic Field" with the values

 

Start End StepsStart End Steps

100  90    5                        0      2000 1000

 

it would generate:

 

Temp   Magnetic Field

100      0

100      1000 

100      2000

95        0

95        1000

95        2000

90        0

90        1000

90        2000

 

Both of these task seem like they should be fairly straightforward, but at the moment I'm just baffled.

 

For task 1 I was thinking I would add some code inside the stacked case structure with another case structrure which IF the start and end are the same it would add the value of steps to the start and if false it wouldn't do anything. The question is how do I extract the correct array value from the previous iteration to make a correct comparison?

 

Task 2: I am not really sure how to go about this. I tried to use two nested while loops which would used the index array function and the loop increment counter to access the next array value but I couldn't get it to extract the constant temperature and then move onto the next temperature once the magnetic field had been incremented.

 

Any help would be greatly appreciated, and I apologise for being stuck on a simple problem. 

 

Thanks in advance 

Download All
0 Kudos
Message 1 of 17
(3,591 Views)

It'd help if you posted the .vi, but regardless: You should only need 1 Index array and 1 Delete from array. If the Index array (which'll give you the 1st item by default) is equal to the Delete from Array (which'll give Last item and Rest of array as outputs) then you can concatenate the Rest of array with the other array, if they're different you can concatenate the full arrays.

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 2 of 17
(3,575 Views)

OK, thanks for the tip I shall have a look. I've also attached the VI so you can see more clearly what I want to do.

 

Thanks

0 Kudos
Message 3 of 17
(3,552 Views)

Try to avoid Stacked sequences, it hides code and makes it alot harder to read. In this case it seems the only difference between the frames is the index, which a foor loop would autoindex for you. And/or make a sub-vi you use instead.

 

I did a quick untested loop of the first structure instead, it should serve as a start.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 17
(3,537 Views)

Thanks for the advice and the code. It doesn't quite work though, it writes the first set of start and end values fine, but if you enter a second one it only writes the first one, and I don't know why. Stepping through the code indicates that it writes #2x4x1 to the array after the loop, and the loop does increment/decrement the second set of values correctly, so I don't know what is wrong.

0 Kudos
Message 5 of 17
(3,519 Views)

Can anyone else suggest why it won't write to the array properly?

0 Kudos
Message 6 of 17
(3,491 Views)

Are you trying to generate a one dimensional array of [Temp, Oe] pairs where the pair never repeats? Thats what it looks like your trying to do in your 1st post.

0 Kudos
Message 7 of 17
(3,484 Views)

I'm trying to do two things as explained in my first post.

 

On the front panel, you enter "start" and "end" values for the "Temp" and "Oe" and the "steps" that you want in to increment/decrement between the start and end values. But what I don't want, is for the End value to be the same as the next start value. So the example I posted in the OP:

 

Start End Steps

100 90     5

90   80     5

 

this will generate two arrrays in the cluster of:

 

100

95

90

 

90

85

80

 

But this has the end value the same as the next start value (of 90).

 

Another example:

Start End Steps

100 90     3

90   80     5

 

This would produce, 2 arrays in the cluster

 

100

97

94

91

 

90

85

80

 

This doesn't need modifying because the end value is not the same as the next start value. This is one of two things I want to do, see me original post for the second one.

 

So Yamaeda kindly suggested instead of using a stacked sequence structure, use a for loop and provided a modified code to help me. However it doesn't work as it only writes one set of values to the array. For example if you set the values:

 

Start End Steps

50     40     2

30     20     5

 

it will only write to the array:

 

50

48

46

44

42

40

 

instead of writing both sets to the array and it should look like this:

 

50

48

46

44

42

40

30

25

20

 

The VIs are attached in mine and Yamaeda's posts. So can anyone tell me why it only writes one set of values to the array, instead of all of them?

 

 

 

0 Kudos
Message 8 of 17
(3,474 Views)

I asked a yes or no question and you just repeated your 1st post without answering my question. I know why it doesn't work I want to make suggestions on how to do what you need. But I need to know what you need, not just what you think you need.

0 Kudos
Message 9 of 17
(3,460 Views)

No.

 

What about my post is unclear?

0 Kudos
Message 10 of 17
(3,458 Views)