LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Replace elements in array

Hello!

 

I am having a 1D array, in which I need to find the lowest (smallest) value that meets a certain criteria. I was thinking to take the lowest value in the array (using the Min/Max function), and check that value towards the criteria. If it is not satisfying the criteria, I was thinking of taking the next one and so on. When I find the lowest value that satisfied the cirteria, I want to return the index. I am not quite sure, but I was thinking that i maybe needed to replace the lowest value with some high value (i.e infinity) to get the looping. However, doesn't quite seems like I can get the looping right. Can anyone help me out on this one?

 

looping.jpg

 

Greetings

Kristoffer

0 Kudos
Message 1 of 10
(3,916 Views)

In order to retain the updated array for the next iteration of the loop, you need to keep it in a shift register, else you continue operation on the original, unchanged array from the left tunnel. Think dataflow!

 

Your code concept seems highly convoluted and it is not clear at all from looking at the code what you want? You have a 1D DBL array and a 2D array of waveforms. Where are they coming from? What's in it? What does it mean? Instead of two successive "index array", use one and wire both indices. Why is the addition inside the loop, it should be outside the loop, etc.

 

Can you attach an actual VI containing typical data?

0 Kudos
Message 2 of 10
(3,911 Views)

Ok, i'll try out with a shift register. The 2D array is actually of type timestamp, and not waveform. The 2D timestamp contains timeintervalls of length decided from front panel, while the 1D array contains the expected production for each timeintervall. The two index array is used since I only want to process the first row (first element) in each column, but yes, I'll see now that I'll could have used only one of them;) I have tried to run the program, create constants and upload it, but seems like the size is getting to big then..

 

Greetings

Kristoffer

0 Kudos
Message 3 of 10
(3,901 Views)

Hello!

 

I reduced the number of datapoints used, so the program is within req. size now! Really hoping that you could help me on this!

 

Greetings

Kristoffer

0 Kudos
Message 4 of 10
(3,888 Views)

Hi,

 

Its not very clear what you are trying to achieve here. Is the the number of index of all the criteria fulfilling values that you need as a result? Can you explain a bit. 

 

In the attached VI, You have auto indexed the for loop with the time stamp array and also wired the N terminal of the for loop to the array size of 1D array. The sizes of both, the time stamp array and the 1D array are different. So which one do you want to really index to the for loop?

 

The Min/Max function's input should be wired from the shift register and not directly from the array. Then only it will get the updated value.

 

Provide these clarifications so that we can help you in a better way.

Regards,
Nitz 

(Give Kudos to Good Answers, Mark it as a Solution if your problem is Solved:smileywink:)  

Message 5 of 10
(3,883 Views)

No, I only need the index of the lowest criteria fulfilling value. If this value is found at several indexes, I would actually liked to returned the one where the first element (from the 2D timestamp array) is closest to a certain criteria (although, I haven't tried to do anything like this yet). The size of the 1D = 2D -1. Since I am only interessting in comparing the first timestamp of each column from the 2D timestamp array (disabled at row 0), they have the same size -1. The last column of the 2D timestamp array is of no interest, and should not be taken into account.

 

Hope that this clearified thing a bit

 

Greetings

Kristoffer

0 Kudos
Message 6 of 10
(3,877 Views)

Hi Kristoffer,

 

Check the attached VI. I believe it is working now. Use Replace array subset function instead of insert into array for add the infinities.

 

Regards,

Nitz

(Give Kudos to Good Answers, Mark it as a Solution if your problem is Solved:smileywink:)  

Message 7 of 10
(3,862 Views)

Thanks! Seems to be a step further to a solution, but unfortunately not quite yet. If you place an indicator right after the yellow array constant on the left hand side of your program, and then run the program, you can see the following: By comparing the "Production each timeintervall" with the newly created "Production each timeintervall 2", you can see that the returned index actually not is the lowest. At index 1759 (which is found by the program) the value is approx. 2.072. However, by looking at i.e index 1763, you can see that the production here was even lower (1.17).Probably only a small tweak or something.

 

Greetings

Kristoffer

0 Kudos
Message 8 of 10
(3,853 Views)

Hi Kristoffer,


Sorry for not checking the code before submitting. I have fixed that mistake and have attached the code here. Have look.

 

Regards,

Nitz

(Give Kudos to Good Answers, Mark it as a Solution if your problem is Solved:smileywink:)  

Message 9 of 10
(3,847 Views)

Nothing to feel sorry about! Just a note to your note inside the code, yes 0 (zero) is also a possible value, and should be checked for!;) Yeah, it surely works better now! However, I am afraid that there is still something that is not quite right. If you run the program, it doesn't seem to take the criteria into consideration. Since the constant in the code is 15:44:18 12.03.12, and the criteria should prevent the program from choosing an index where the first element is less than 2+1 =3 hours away from the constant. Any idea about this?

 

Greetings

Kristoffer

0 Kudos
Message 10 of 10
(3,840 Views)