LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Set first and last "X" values of array to a value

Solved!
Go to solution

If I have a 1D DBL array, how can I set the first and last (e.g.) 100 values to, say, 0?

 

I can think of doing a for loop for both the first and last segments, but wonder if there's a more elegant way.  

0 Kudos
Message 1 of 7
(2,827 Views)

Hi ap8888,

you can initialize an array with 100 elements of 0. Use the replace array subset function to replace the data from your array with the initialized elements.

 

Mike

Message 2 of 7
(2,825 Views)

Thanks. 

 

But how do I replace elements 1 through 100? In MATLAB I would likely type, A(1:100)=0.  

 

Moreover how do I set the last 100 to 0?  

 

In other words I don't want to push my data over to fit the new 100. I want to replace.  

Message Edited by ap8888 on 03-16-2010 03:58 PM
Message Edited by ap8888 on 03-16-2010 03:59 PM
0 Kudos
Message 3 of 7
(2,814 Views)
Open up the context help for Replace Array Subset.  It will tell you what each index means.  For the last 100 you need to do the same thing but it will be the length of the array minus 100 as the starting index.
Message 4 of 7
(2,810 Views)
This is an easy way where you do not have to worry about the size of the orginal 1D array
Tim
GHSP
Message 5 of 7
(2,803 Views)
Solution
Accepted by topic author ap8888
OK here is the first 100 and last 100. I didn't read that the first time.
Message Edited by aeastet on 03-16-2010 05:08 PM
Tim
GHSP
Message 6 of 7
(2,801 Views)
Here is a more flexible version.
Tim
GHSP
Message 7 of 7
(2,797 Views)