LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Extract a column of data...

Hi,

 

I have data in a text file, see attached example srm.txt, set out in X columns wide of Y lines long. Each column is of varying width of hex data.

 

I need to extract column Z from each line. Extract the max, min and average for that column and store this data.

 

This is repeated for Z+1 until the last column X.

 

I have been scanning the discussions and trying to adapt what I have found with little success.

 

I am mainly work with what I asked befor in “Line extract and split from files” but this new request differ a bit from the solution provided at that time.

 

Any pointers to examples or some direction would be much appreciated.

 

Thanks

Simon

 

0 Kudos
Message 1 of 5
(2,924 Views)

Hi Srm27,

 

As a bit of guidance, the most popular way to read in the data from a file is through the ReadLine funciton in LabWindows, RobertoBozzolo has given a good explanation on how this works across the span of this thread. There are other ways to read from files such as through ScanFile, a nice list of which can be used can be found on this page but bear in mind cases in which you cannot read hexadecimal numbers from a file such as with the FileToArray function.

 

In terms of statistical functions within LabWindows you have these available to you, and if you want to convert from hex to floating point you can use this as a reference.

 

I hope this helps!

Best regards,

Mark W
Applications Engineer
National Instruments UK & Ireland
0 Kudos
Message 2 of 5
(2,885 Views)

 

Hi,

 

Thanks for the pointers.

 

I have the columns into the array and using the calculations can get the average.

 

But I am still struggling with the conversion from hex to decimal. The link provided is not working.

 

At the moment I read in the value, a stringSmiley Frustrated, from the file and on converting I think in ends up as decimal, val, with the following

                     val = atoi(items[i]);

  

Problem is if I read a true hex, with letters, I return 0.

 

If I read from the file F434, for example I need to get it to 62516 so I can work on it, i.e. stats. 

 

1 can I convert directly to hex?

2 failing that how do I convert val from int to hex?

 

I will may be farm from what should be done, can anyone help?

 

Thanks

Simon

0 Kudos
Message 3 of 5
(2,867 Views)

You should use Scan from Formatting and I/O Library or sscanf from Ansi_C Library to decode hex digits, both with "%x" scanning code; documentation on the latter can be fonud in any good C reference manual. Both of them are powerful yet complex commands that can help you in extracting a specific column from your data while analyzing a line of text.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 4 of 5
(2,858 Views)

 

 

 

 

 

 

 

0 Kudos
Message 5 of 5
(2,842 Views)