LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating an array via two cases element-by-element

Hi all.

Okay, I'll try to explain this as best I can. I am reading in a text file that contains numerical data line-by-line. I parse the line and, depending on what the number is, I handle the data in one of two ways. In the first case, the number is in sequential order with the number before it. In that case, I insert the data from the text file into the array via Insert Into Array passed into a local variable of my resultant array.

In the 2nd case, when the number is not sequential, I want to pass NaN into a local variable of the array just as I would pass data in the first case. For some reason, this operation is giving me an empty array.

Does the array not grow in size incrementally as I insert data into it? If not, how do I make this work without having prior knowledge of how big the array will end up being?

I hope this makes sense.

Thanks!
Ryan
0 Kudos
Message 1 of 14
(3,383 Views)

Ryan,

This can be done by parsing, but it is harder.  The trick is to get the text string into an array then compare element by element in a for loop.  I assume sequential values are values greater than the previous value.  If you need to "pad" missing sequential numbers, the attached VI will not work for you, additional logic will be required to do that.  But if you only care about increasing numbers then the vi should work. I hope this helps

Chris Co

0 Kudos
Message 2 of 14
(3,374 Views)
Thanks Chris, but I actually do need to "pad" my array with NaN's. For instance, if the index I read in is 64, and the next one is 67, I need to insert two NaN elements between the data at 64 and the one at 67. Does that make sense?

Ryan
0 Kudos
Message 3 of 14
(3,371 Views)

This is revised and didn't have time to make it work for same value or smaller numbers (works just array size is off) easy fix with array manuplitation.

 

Chris Co

0 Kudos
Message 4 of 14
(3,364 Views)
I assume you are dealing with an integer array. However, the output array needs to be SGL or DBL, else NaN is not available.
"Insert into array" is a relatively inefficient operation since the array size changes with each use. This causes constant memory allocations and low performance. It is always better to operate on fixed sized arrays. Reading a file one value at a time is also very inefficient. Read all values at once!
 
I would do the following:
  1. Read the entire file, creating an integer array of all values in the file.
  2. Initialize an array with a size corresponding to the highest number in your input array, containing all NaNs.
  3. Now, for every integer N in the input array, replace the array element at the position N with a value of N.
  4. Voila!

Of course depending on the range and offset of your values, you can do a transform of the index to save array elements.

 

Message Edited by altenbach on 12-04-2006 11:07 PM

Message 5 of 14
(3,365 Views)
Here's what I had in mind (LabVIEW 8.0). Modify as needed.
Message 6 of 14
(3,357 Views)

Altenbach,

Brilliant!Smiley Happy

0 Kudos
Message 7 of 14
(3,354 Views)
Thank you, that helped a lot! Now I've got the gaps and data plotting correctly.

Now I've faced another obstacle, which I had solved in a previous version of the program, but am having trouble reproducing. I need to plot two arrays on a single waveform. Sounds simple, eh? Well, one of the arrays is plotting just fine, but the other doesn't show up. I have the waveform graph set to display 2 plots, so that isn't the problem. I pass the two pieces of data into their own Build Array functions before passing them on to be indexed at the end of my while-loop. I then use another Build Array function outside the while-loop to pair the two arrays into one, before passing it on to be graphed.

This method has worked before, but now it's not. Am I making life too difficult?

Thanks again everyone!

Ryan
0 Kudos
Message 8 of 14
(3,336 Views)

Your description is a bit confusing. It would be much clearer for us if you could attach your code. 🙂

(What is "a piece of data"? Why all these "built array" functions?)

0 Kudos
Message 9 of 14
(3,334 Views)
Alright, I gave it a try verbally, so now here is my latest version of my program. I haven't made it "pretty" yet (functionality comes first) so please forgive me. The text attachment is an example of the text file I read in.

Ryan
Download All
0 Kudos
Message 10 of 14
(3,331 Views)