Jump to content


Photo
- - - - -

import data from txt file


  • Please log in to reply
5 replies to this topic

#1 Mars Su

Mars Su

    Active

  • Members
  • Pip
  • 22 posts
  • Location:Stuttgart Germany
  • Version:LabVIEW 2009
  • Since:2008

Posted 05 August 2010 - 11:59 AM

Hello Lava fellows,

I found that LabVIEW is not so intelligent at data import compared to Matlab.(Just personal view! )
I got a set of data stored in txt file. The good thing is that it's pure numeric data, but the bad thing is that the delimiters between columns are not uniform, sometimes space, sometimes tab.
Then I try to import the data with LabVIEW. I tried 2 ways.
1. load in data by "read from spreadsheet". This doesn't work
2. load in data by "read from txt file", then "string to spreadsheet array", it failed again.
I guess the problem is that the delimiter symbol is not consistent.

Then I give up and turn to Matlab, just one use command "load" that's all. The data is imported and stored as a 2d array.

Of course I can first read the txt file and then use string functions to replace all the space with tab (the worst thing is that even the number of space between columns are not equivalent.)
and then convert string to array. But this is really time consuming. I wish LabVIEW could be as intelligent as Matlab in the field of data import.

Maybe there are some high level technique exist in LabVIEW in this field that I am not aware...

Please be kind to share your ideas here

Thanks

#2 hooovahh

hooovahh

    Just cause I dont care doesnt mean I don't understand

  • Moderators
  • 1,313 posts
  • Version:LabVIEW 2013
  • Since:2004

Posted 05 August 2010 - 01:53 PM

Attached is a VI that I think does what you want. It opens the file as a text file. Then processes each line one at a time. It will take each line and replace all spaces with tabs. Then it will convert that string to an array using the tab as the delimiter. This will generate several elements that have no value, say if you had a tab followed by another tab. So we then filter the 1D array removing all the empty elements. I didn't know if you had any OpenG stuff installed so I made the OpenG filter 1D an inline VI. BTW saved in 8.6

Attached Files


"Maybe Hoovah is really Crelf's alter-ego, which he uses to irk people?" - Gary Rubin
"Seemingly minor changes....can mean the difference between a working app and a quivering heap of unresponsive code." - David Boyd
"Using unofficial features of LabVIEW is cat nip laced with poison."


#3 Mars Su

Mars Su

    Active

  • Members
  • Pip
  • 22 posts
  • Location:Stuttgart Germany
  • Version:LabVIEW 2009
  • Since:2008

Posted 05 August 2010 - 02:35 PM

Attached is a VI that I think does what you want. It opens the file as a text file. Then processes each line one at a time. It will take each line and replace all spaces with tabs. Then it will convert that string to an array using the tab as the delimiter. This will generate several elements that have no value, say if you had a tab followed by another tab. So we then filter the 1D array removing all the empty elements. I didn't know if you had any OpenG stuff installed so I made the OpenG filter 1D an inline VI. BTW saved in 8.6


Thanks your VI works perfectly. I know that it can be done in this way. I just want to say LabVIEW should provide some kind of functions like yours to make the data import more intelligent like matlab did.
Well they should maybe just adopt your VI. :thumbup1:

#4 crelf

crelf

    I'm a LAVA, not a fighter.

  • V I Engineering, Inc.
  • 5,775 posts
  • Version:LabVIEW 2013
  • Since:1993

Posted 07 August 2010 - 07:48 PM

I found that LabVIEW is not so intelligent at data import compared to Matlab.(Just personal view! )

LabVIEW can do everything that matlab can wrt to file loading - unfotunately LabVIEW will do what it asks you to, which is not necessarily what you *want* it to :)

I got a set of data stored in txt file. The good thing is that it's pure numeric data, but the bad thing is that the delimiters between columns are not uniform, sometimes space, sometimes tab

I'm glad LabVIEW doesn't read that file by default - it's an edge case, and if it read files like that by default I might think it'll try to read a file that I didn't want it to.

Forum curteosy note: In future, please upload both an example of the file that you're having issues with, as well as example code that shows what you've tried - it's easier for us to make changes to what you've done than star from scratch on somthing that might not quite work for what you wanted.

crelf

 

 

Copyright 2004-2014 Christopher G. Relf. Some Rights Reserved.  This posting is licensed under a Creative Commons Attribution 2.5 License.


#5 Mars Su

Mars Su

    Active

  • Members
  • Pip
  • 22 posts
  • Location:Stuttgart Germany
  • Version:LabVIEW 2009
  • Since:2008

Posted 08 August 2010 - 07:52 AM

Thanks crelf.

First of all, thanks for your hint about how to make a post in a more understandable and clear way.
Secondly, I agree with you about the opinion that LabVIEW can do everything and it does what we ask it to but not what we want it to.
What I want to express here is that it will be great if LabVIEW provide functions that do as what I we want it to. (like what hooovahh did). It's not the matter of it is able to or not, it's the matter of how convenient it is. Every one expect that LV provide some epress build-in VIs so that users dont need to program it by our own even we know how to do it. And this is why that Lava, Open G .etc. are so popular.

#6 TMcGuire

TMcGuire

    I've come back for more.

  • Members
  • 2 posts
  • Version:LabVIEW 7.1
  • Since:2007

Posted 08 September 2010 - 12:42 PM

Are any of you able to save the Open_data_File in Version 7.1?