LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Comparing elements of array with previous ones and insert index of elements where v[i+1]<v[i] in another array

Solved!
Go to solution

Hi,

i'm new to Labview. I'd like to get some helps to solve this kind of problem. I've got an array of integer in input and i must compare every element with previous one. If the element in i-th position is less than previous(i-1 th) then i must insert index of this element in another array in output, else if the element in i-th position is greather than previous(i-1 th) then i must insert zero in output array.

 

Example

Array in input=[1,36,2,3,43,6,8,1]

Array in output=[0,2,0,0,5,0,7]

 

 

Any helps would be kindly appreciated. Thank you so much.

0 Kudos
Message 1 of 17
(7,273 Views)

Start with below links to learn about LabVIEW programming 

NI Learning Center

NI Getting Started

LabVEW Basics

3 Hour LabVIEW Introduction 

6 Hour LabVIEW Introduction 

LabVIEW Graphical Programming Course

Using the Context Help Window

LabVIEW Inbuilt Examples

Thanks
uday
0 Kudos
Message 2 of 17
(7,267 Views)
Solution
Accepted by topic author ptavernise2345

Hi ptavernise,

 

you need a FOR loop with a shift register.

By autoindexing through your input array you can compare the current element with the previous one you have stored in the shift register.

Connect the result of the comparison to a Select node and output either zero or the loop ietration count…

 

This is very basic LabVIEW stuff - you surely have seen the Getting Started section in the header of the LabVIEW board…

 

 

Spoiler

A different solution than the one described above:

 

check.png

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 17
(7,262 Views)

This is the VI. I don't know why it doesn't work?

0 Kudos
Message 4 of 17
(7,248 Views)
Solution
Accepted by topic author ptavernise2345

Hi ptavernise,

 

you don't compare with previous value. Instead you compare with the previous result (zero or index)…

Additionally you shouldn't wire a constant to "N" when you want to employ autoindexing.

And you should create an array output (using autoindexing again) to create your "array 2"!

 

Why did you mark your own question with a erranous VI as solution?

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 5 of 17
(7,234 Views)

Hi,

i'm new to labview.I have a signal with its samples in an array and i like to find local maxima and minima, report it on the waveform and detect values of local maxima and minima. For example if we have i, i+1, i+2, i+3, i+4 we can define local maxima v[i+2] if v[i+2]>v[i],v[i+2]>v[i+1],v[i+2]>v[i+3],v[i+2]>v[i+4]. If we have i, i+1, i+2, i+3, i+4 we can define local minima v[i+2] if v[i+2]<v[i],v[i+2]<v[i+1],v[i+2]<v[i+3],v[i+2]<v[i+4].

 

How can i do?

 

Thank you so much

 

any help would be kindly appreciated

0 Kudos
Message 6 of 17
(7,196 Views)

Hi ptavernise,

 

so you already got solutions to find elements with x[i]<x[i-1], but you struggle to find elements with x[i]>x[i-1]?

 

Please stick with your threads as long the topic doesn't change!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 7 of 17
(7,185 Views)

I know the definition but i don't know how to implement vi.This is the main problem.

0 Kudos
Message 8 of 17
(7,178 Views)

Hi ptavernise,

 

you really should learn how to use shift registers…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 9 of 17
(7,174 Views)

This is the VI i have created. I cannot understand where is the error.Please help me, i really appreciate your help.

 

Thank you so much for helping me.

0 Kudos
Message 10 of 17
(7,166 Views)