05-13-2020 09:45 AM
Hi,
I want to store my data into a .txt file. I did this as shown in the attached image.
However, the data does not have a constant size. By using the \t delimiters I get sometimes the right column representation in my text file:
Force Pressure 1 Pressure 2
100.3 285.8 503.29
But sometimes I get:
Force Pressure 1 Pressure 2
1000032.6 82.5 78.236
I was wondering if it is possible to set a constant tab size to get a correct column representation.
Note, I know that with TDMS files this is possible. However, I highly prefer a .txt file because the data will be processed in Matlab. And loading large TDMS files (which I am supposed to do) in Matlab is horrible.
Thanks in advance.
Solved! Go to Solution.
05-13-2020 09:55 AM
This is not a LabVIEW issues, but an OS issue. The OS defines how many "spaces" a tab takes up upon display. Heck that may even vary from application to application. It is certainly different between Notepad and Word (where the distance between tab stops is a formatting property.)
I think you are confusing appearances with data representation. In your shown example, your appearance is based on the HTML formatting of the NI website. The problem is that if your title is dramatically different in length from your data element, enough that one or the other reaches beyond the arbitrary tab stop of whatever program you are using the data, it is never going to appear the way you want.
You say you are doing this in Matlab. If it is to programmatically read the file and analyze, don't worry about appearance. Doing anything will just complicate the parsing of the file in to data.
If it is just to display the data in some text window and you don't care about extra characters screwing things up, first you need to make sure that text window is set up some monospaced font like Courier. You could send the data out with string formatting codes that are fixed some over places. So a format code of %-16s would take any string up to 16 characters. Any missing characters would be filled with spaces. So "Force" would be followed by 11 spaces.
05-13-2020 10:42 AM
@RavensFan wrote:
This is not a LabVIEW issues, but an OS issue.
It's not really an OS issue, but a text editor issue. In Word, UltraEdit, etc, I can set the tab size. I don't think Notepad allows you to. So if there is an option to set the tab size, just make it bigger.
Alternatively, just open the text file in Excel. Excel will read a tab delimited text file with no issues and the columns will be properly filled in.
05-13-2020 11:38 AM
Change your file extension from .txt to .tdl. That will let Excel open the file and will show the data properly formatted, and Matlab can still read it in as tab-delimited.
(tdl = tab delimited file, like csv = comma separated values)
05-13-2020 01:50 PM
@BertMcMahan wrote:
Change your file extension from .txt to .tdl.
I have never had to do that. Excel opens up txt files for me with no issues. I do it all the time.
05-13-2020 01:57 PM
Thank you for your fast reply.
@RavensFan wrote:
So a format code of %-16s would take any string up to 16 characters. Any missing characters would be filled with spaces. So "Force" would be followed by 11 spaces.
I implemented this. I know the maximum possible digits for each parameter. Using this method I am able to reserve for every parameter the maximum needed space.
Thanks!
05-13-2020 02:02 PM - edited 05-13-2020 02:03 PM
@BertMcMahan, Thanks for your reply,
I implemented this and it works indeed, so it is definitely a possible solution to the problem.
However, I like the constant tab space as suggested by RavensFan slightly more.
Thank you for your suggestion!
05-13-2020 06:23 PM
@crossrulz wrote:
@BertMcMahan wrote:
Change your file extension from .txt to .tdl.
I have never had to do that. Excel opens up txt files for me with no issues. I do it all the time.
Same here, but Excel will open automatically with a .tdl file extension. .txt opens in Notepad, and you have to manually right click->open with -> Excel (or open Excel, then File-Open, etc).
In my experience it's much more likely to want to read tab-delimited data with Excel than a text editor, but it's no hard and fast rule.
05-13-2020 07:13 PM
@BertMcMahan wrote:Same here, but Excel will open automatically with a .tdl file extension.
I'm not having that experience. I just changed one of my data files to a tdl extension and now Windows has no clue what to do with the file. So I'm guessing you configured Windows to open a tdl file with Excel.
I typically just open Excel and then drag my files over if I really need to do something with them in Excel. Otherwise, I have Ultra Edit set the tabs fairly large so my columns usually line up.
05-13-2020 08:31 PM - edited 05-13-2020 08:32 PM
@crossrulz wrote:
@BertMcMahan wrote:Same here, but Excel will open automatically with a .tdl file extension.
I'm not having that experience. I just changed one of my data files to a tdl extension and now Windows has no clue what to do with the file. So I'm guessing you configured Windows to open a tdl file with Excel.
I typically just open Excel and then drag my files over if I really need to do something with them in Excel. Otherwise, I have Ultra Edit set the tabs fairly large so my columns usually line up.
Well it looks like I owe the forum an apology, you're right.🤐 Thanks for letting me know. My Excel does recognize *.tdl files but I can't for the life of me remember setting that up. I must be getting mixed up with csv, which I think Excel will open natively (but who knows, I could've made that setting years ago and forgotten too).
It's funny because I basically never use the tdl file extension, so I wouldn't have a reason to set it up to open in Excel automatically. We use .csv for delimited files around here.
Anyway, to the OP and anyone else, this is apparently a setting on my machine that I made several years ago and forgot. I can't go back and edit my above post anymore so hopefully it doesn't confuse anyone else.
It *is* a fairly convenient setting though 🙂