LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to build an array based on inputs from a text file

Hi

I have ta text file that has the following format. The apmlitude is the first value then I have the start index number and last index number

Other index values in between should be zero

 

(amplitide, start index number, end index number)

2, 2 ,3

4, 6, 7

5, 10,11

 

using this format I should make the foloowing array

 

0,0,2,2,0,0,4,4,0,0,5,5

 

Could you please help me to implement it in LabVIEW

Thanks

0 Kudos
Message 1 of 16
(3,794 Views)

This looks like homework and seems quite trivial once you are familiar with array operations.

 

What have you tried so far?

0 Kudos
Message 2 of 16
(3,790 Views)

Hi Tintin,

 

This is how I would go about it:

 

1) Initialize an array filled with zeroes, size = last index or however large you're going to need the array to be.

2) Pull out columns 2 and 3 from your spreadsheet, subtract 2 from 3 to give you the "index delta" for each row

3) Using column 1 and the new index delta array, initialize sub-arrays of value(amplitude/column 1) and size(index delta)

4) Use replace array subset and insert these sub-arrays at index(start index number) in the array we initialized in step 1)

 

This might be overkill, and depending on the size of your data sets may not be worth it- if your text file will always be sequential then you can probably just do an increment-index-and-check-value algorithm.

 

Regards,

Tom L.
0 Kudos
Message 3 of 16
(3,785 Views)

Hi Outlaw

 

Could you please show me in a sample vi , I tried to follow your instruction but I don't understand part 3 and 4

Thanks

0 Kudos
Message 4 of 16
(3,767 Views)

Show us what you got after doing steps 1 and 2.

Craig H. | CLA CTA CLED | Applications Engineer | NI Employee 2012-2023
Message 5 of 16
(3,761 Views)

Please find attached my vi

Thanks

0 Kudos
Message 6 of 16
(3,752 Views)

please ignore my previous post

0 Kudos
Message 7 of 16
(3,749 Views)

A few notes:

 

- You'll want to use the Initialize Array function for 1) and 3) (if this is, in fact, how you want to do this.)  This function takes two inputs when initializing a 1D array- element value and array size.   

 

- Change the polymorphic instance of Read From Spreadsheet File.vi to "Double" or "Integer"- there's no reason to read in these numeric values as strings and convert them later.

 

- Will the text file always contain 12 elements worth of data?  If not, you'll need to change your logic for the number of elements to initialize.

 

As Altenbach said, this seems a lot like a basic logic/homework problem.  My suggestion was only that-a suggestion.  It is not the only way to do this. Figure out a sequence of steps to get you from point A to point B before you jump in and start coding. 

 

Regards,

 

Tom L.
0 Kudos
Message 8 of 16
(3,739 Views)

- Thanks for letteing me know, I will use Initialize Array function

-I will change to instance to double

-Yes, for now it has 12 elements 

 

But my main problems are step 3 and 4. I don't understand how to do 3 and 4. Could you please help me on those part.

 

0 Kudos
Message 9 of 16
(3,735 Views)

Search for the functions Initialize Array and also Replace Array Subset and read up on the information in the help file.

0 Kudos
Message 10 of 16
(3,730 Views)