Jump to content

import data from txt file


Recommended Posts

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

Link to comment

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

Open Data File.vi

Link to comment

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:

Link to comment
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.

Link to comment

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.

Link to comment
  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.