ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Replace Array Elements

Solved!
Go to solution

Hello all,

 

Can you please tell me if anyone have better idea. I want to replace “-ve” numbers in array between “+ve” Numbers.

 

Sometimes bit difficult to get the better Idea. 😛 😛

Munna
Download All
0 Kudos
Message 1 of 8
(3,947 Views)

Hi munna232,

 

You want to  replace +ve numbers instead of -ve numbers in an array or to place -ve numbers between +ve numbers in array ?

0 Kudos
Message 2 of 8
(3,935 Views)

You mean something like this?

 

ReplaceArray_anand.png

-----

The best solution is the one you find it by yourself
0 Kudos
Message 3 of 8
(3,919 Views)

I want to replace only -ve numbers between +ve Numebrs like my sample VI.

 

Suppose my data is,

 

-1,-1,2,-1,-1,-1,5,6,-1,-1,-1,8,9,10,-1,-1

 

Result: -1,-1,2,100,100,100,5,6,100,100,100,8,9,10,-1,-1

Munna
0 Kudos
Message 4 of 8
(3,885 Views)

Hi Munna,

 

search the first and the last positive number in your array. Then replace negative numbers only between them - use their index as start/stop-condition of your loop…

 

first = index of first positive number
last  = index of last positive number

FOR i= first TO last
  if a[i]<0 then a[i]=100
NEXT

 

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 8
(3,876 Views)

Hi GerdW,

 

Could you please give me Snippet/sample VI.

Munna
0 Kudos
Message 6 of 8
(3,868 Views)

Check this.

ReplaceArray_anand-Mod.png

 

Is it Rubed Smiley Wink

-----

The best solution is the one you find it by yourself
0 Kudos
Message 7 of 8
(3,864 Views)
Solution
Accepted by topic author Munna232

Here's what I would do.

 

 

Download All
0 Kudos
Message 8 of 8
(3,844 Views)