LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I have a VI and an attched .txt data file. Now I want to read the data from the .txt file and display it as an array in the front panel. But the result is not right. Any help?

I have a VI and an attched .txt data file. Now I want to read the data from the .txt file and display it as an array in the front panel. But the result is not right. Any help?
Download All
0 Kudos
Message 1 of 10
(3,504 Views)
You need to convert the numbers in your string, not type cast them. Review the help for the type cast function and the string conversion functions to understand the difference.
One easy way to deal with spreadsheet-style text files is to use Read From Spreadsheet File.vi on the File I/O palette. You can specify the numeric format and the delimiter. It will read the entire file and create a numeric array for you. Look at its help to see its options.
0 Kudos
Message 2 of 10
(3,504 Views)
Data file is the same one as above. I use the string conversion functions.Here is the VI.But the array is not right. Any help?
0 Kudos
Message 4 of 10
(3,504 Views)
Using the Read From Spreadsheet File. Here is the attached VI. Only the first number came out. So any good suggestion?
0 Kudos
Message 5 of 10
(3,504 Views)
Sorry, the VI that uses the Read From Spreadsheet File is Here. Only the first number came out. So any good suggestion
0 Kudos
Message 6 of 10
(3,504 Views)
The problem is in the delimiters in your text file. By default, Read From Spreadsheet File.vi expects a tab delimited file. You can specify a delimiter (like a space), but Read From Spreadsheet File.vi has a problem with repeated delimiters: if you specify a single space as a delimiter and Read From Spreadsheet File.vi finds two spaces back-to-back, it stops reading that line. Your file (as I got it from your earlier post) is delimited by 4 spaces.
Here are some of your choices to fix your problem.
1. Change the source file to a tab delimited file. Your VI will then run as is.
2. Change the source file to be delimited by a single space (rather than 4), then wire a string constant containing one space to the delimiter input of Read From Spreadsheet File.vi.
3. Wire a string constant containing 4 spaces to the delimiter input of Read From Spreadsheet File.vi. Then your text file will run as is.
Depending on where your text file comes from (see more comments below), I'd vote for choice 1: a tab delimited text file. It's the most common text output of spreadsheet programs.
Comments for choices 1 and 2: Where does the text file come from? Is it automatically generated or manually generated? Will it be generated multiple times or just once? If it's manually generated or generated just once, you can use any text editor to change 4 spaces to a tab or to a single space. Note: if you want to change it to a tab delimited file, you can't enter a tab directly into a box in the search & replace dialog of many programs like notepad, but you can do a cut and paste. Before you start your search and replace (just in the text window of the editor), press tab. A tab character will be entered. Press Shift-LeftArrow (not Backspace) to highlight the tab character. Press Ctrl-X to cut the tab character. Start your search and replace (Ctrl-H in notepad in Windows 2000). Click into the Find What box. Enter four spaces. Click into the Replace With box. Press Ctrl-V to paste the tab character. And another thing: older versions of notepad don't have search and replace. Use any editor or word processor that does.
0 Kudos
Message 7 of 10
(3,504 Views)
I need to correct one thing I just said. When Read From Spreadsheet File.vi encounters multiple delimiters (e.g., you specified a single space and it finds two spaces), it doesn't stop reading the line: it reads an entry=0.
For example, if you specify one space as your delimiter and file contains the following:
0.11270.13700.1628
The output from Read From Spreadsheet File.vi will be
0.1127
0
0
0
0.1370
0
0
0
0.1628
0 Kudos
Message 8 of 10
(3,504 Views)
Hi,

I am including a vi which reads the data from the text file & displays in the 1D array.

Hope this helps.

Best Regards,
Nirmal Sharma
India
0 Kudos
Message 10 of 10
(3,504 Views)