10-31-2011 07:41 AM - last edited on 11-11-2011 10:38 AM by JordanG
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
10-31-2011 11:05 AM
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
10-31-2011 08:14 PM
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
11-01-2011 02:55 AM
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
11-01-2011 05:56 PM
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.
11-02-2011 06:07 PM
Can anyone else suggest why it won't write to the array properly?
11-02-2011 08:24 PM
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.
11-03-2011 03:56 AM
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?
11-03-2011 10:54 AM
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.
11-03-2011 10:59 AM
No.
What about my post is unclear?