03-28-2017 08:31 AM
Hi!
I have a following problem, I've got several files generated in other LabVIEW program that contain measurement values, and I wanted to read them with another vi. However, the values stored in scientific format (%.6e) are not read correctly, only the 1st digit is read. I tried manipulating the formats and several attempts with conversion, but it just won't run properly.
The file I was reading looks like that:
Angles POW1_M POW2_M TRANS_M POW1_R_M TRANS_NL_M
0.000000E+0 1.484676E-3 5.374000E-5 3.619645E-2 2.146400E-5 3.675103E-2
1.000000E+0 1.350296E-3 4.886000E-5 3.618466E-2 1.953800E-5 3.687208E-2
2.000000E+0 1.216055E-3 4.350000E-5 3.577140E-2 1.761400E-5 3.659821E-2
3.000000E+0 1.098281E-3 3.972000E-5 3.616561E-2 1.592600E-5 3.714594E-2
4.000000E+0 1.016509E-3 3.702000E-5 3.641878E-2 1.475400E-5 3.751459E-2
5.000000E+0 9.705989E-4 3.540000E-5 3.647233E-2 1.409600E-5 3.763346E-2
6.000000E+0 9.562259E-4 3.502000E-5 3.662314E-2 1.389000E-5 3.780949E-2
7.000000E+0 9.722734E-4 3.596000E-5 3.698548E-2 1.412000E-5 3.816057E-2
8.000000E+0 1.019579E-3 3.798000E-5 3.725069E-2 1.479800E-5 3.836724E-2
9.000000E+0 1.103583E-3 4.138000E-5 3.749603E-2 1.600200E-5 3.850539E-2
1.000000E+1 1.215776E-3 4.572000E-5 3.760561E-2 1.761000E-5 3.847515E-2
1.100000E+1 1.362436E-3 5.162000E-5 3.788802E-2 1.971200E-5 3.859453E-2
1.200000E+1 1.528492E-3 5.854000E-5 3.829918E-2 2.209200E-5 3.884355E-2
1.300000E+1 1.739482E-3 6.686000E-5 3.843674E-2 2.511600E-5 3.880018E-2
1.400000E+1 1.979217E-3 7.584000E-5 3.831819E-2 2.855200E-5 3.851260E-2
Does anybody have an idea what might be wrong, or what to do to fix it?
Solved! Go to Solution.
03-28-2017 08:40 AM - edited 03-28-2017 08:46 AM
I think the format specifier you use is correct, and actually you do get proper numbers. You just do not see it in that format 🙂
Right click the number indicator, and change the display format properly:
edit: if this is not the problem, could you attach your data file so we can have a look?
03-28-2017 08:54 AM
It is more likely that the problem is your regional setting of , vs . in decimal numbers.
Try to have the Format like: %.;%.6e
03-28-2017 09:00 AM
@dkfire wrote:
It is more likely that the problem is your regional setting of , vs . in decimal numbers.
Try to have the Format like: %.;%.6e
Good find. I work in Germany. Whenever I deal with a PC, my first thing is to change the separator from comma to dot, in the Environmental settings in Windows... 🙂
03-28-2017 09:13 AM - edited 03-28-2017 09:14 AM
Unfortunately it's not the display, I've tried it before and once again now to double check.
When trying %,6e I get the array full of zeros. I've already tried such formats as %.3f or even %s. The only case when I would see the real values is when I treat the whole file as array of strings, but then I couldn't find a way to convert the scientific notation numbers from string to an actual value. I'm attaching the source file.
03-28-2017 09:18 AM - edited 03-28-2017 09:19 AM
And what about my format?
Try %.;%.6e
And remember that is the full format string!
03-28-2017 09:33 AM - edited 03-28-2017 09:45 AM
This does not work for you?
Because it looks like this when I run it...
The trick is you have to set your indicator's (the array) display format properly.
Oh yeah the first row is all zeros because that is the headers in your text file, and you can't have text in a numeric in array.
You might need to adjust the Significant Digits to match your file too (6 is the default so there is some rounding in the display)
03-28-2017 10:39 AM
As you clearly can see in the image on the front panel, LabVIEW displays the numbers with a decimal comma in the numeric controls. This means that your Windows regional settings are configured to use a decimal comma.
Now the Spreadsheet functions use standard string to number conversion function, which without further specification will assume the decimal separator character from the regional setting.
But!!! Your file contains numbers that use decimal points!! Can you see the disconnect?
And the solution is of course to use the format string as proposed by dkfire and which you seem to have ignored so far!
03-28-2017 10:50 AM
dkfire, I tried it before but I made a mistake in characters, now I've tried it again and it works! Thank you, can you explain what does the format mean exactly, with this "double type declaration" ?
03-28-2017 10:56 AM - edited 03-28-2017 10:57 AM
The online help to the Scan from String Function, which is in fact the function that LabVIEW internally uses in the Read Spreadsheet function, has to say this:
Localization Codes Characters that determine if LabVIEW uses a decimal or comma to separate
the whole number from the decimal part of the number. These codes control the decimal separator
for numeric output. These codes do not cause any input or output to occur. They change the
decimal separator for all further inputs and outputs until they find the next %;. %,; Comma decimal separator. %.; Period decimal separator. %; System default separator. If you do not specify a separator, LabVIEW uses the system default separator.