f



Getting float values from a formatted text file

Hi All
I want to read certain values from text file and need help.

My text file looks like the following

                                                               32 Fed 2044 25:61:61
Asdfg-Asdfg


Data Unavailable


      Yaqw (UUUUU)          Qwe (321) (deg)    Asdfg (321) (deg)    Yxcv (321) (deg)
-----------------------    ---------------    -----------------    ----------------
32 Def 2022 10:00:00.040             56.001               -0.001               0.137
32 Def 2022 10:00:00.060             56.000               -0.001               0.112
32 Def 2022 10:00:00.080             56.000               -0.001               0.112

      Yaqw (UTCG)             i (re)        h (re)      g (re) 
-----------------------    -----------    ---------    --------
32 Def 2022 10:00:00.000    6378.139002    -0.000844    0.000000
32 Def 2022 10:00:00.020    6378.139001    -0.000504    0.000000
32 Def 2022 10:00:00.040    6378.139001    -0.000255    0.000000


I want the values 56.001, -0.001, 0.137, 6378.139002 etc.. in an array..

I have written the follownig code but it doesn't work. It returns error 'First argument must be a string'
0
3/27/2013 5:41:13 PM
comp.soft-sys.matlab 211266 articles. 23 followers. lunamoonmoon (257) is leader. Post Follow

2 Replies
460 Views

Similar Articles

[PageSpeed] 38

On 3/27/2013 12:41 PM, Abubakar Rehman wrote:
....

> My text file looks like the following
>
> 32 Fed 2044 25:61:61
> Asdfg-Asdfg
>
>
> Data Unavailable
>
>
> Yaqw (UUUUU) Qwe (321) (deg) Asdfg (321) (deg) Yxcv (321) (deg)
> ----------------------- --------------- ----------------- ----------------
> 32 Def 2022 10:00:00.040 56.001 -0.001 0.137
> 32 Def 2022 10:00:00.060 56.000 -0.001 0.112
> 32 Def 2022 10:00:00.080 56.000 -0.001 0.112
>
> Yaqw (UTCG) i (re) h (re) g (re) ------....--------- --------
> 32 Def 2022 10:00:00.000 6378.139002 -0.000844 0.000000
> 32 Def 2022 10:00:00.020 6378.139001 -0.000504 0.000000
> 32 Def 2022 10:00:00.040 6378.139001 -0.000255 0.000000
>
>
> I want the values 56.001, -0.001, 0.137, 6378.139002 etc.. in an array..
>
> I have written the follownig code but it doesn't work. It returns error
> 'First argument must be a string'

Oh, for Fortan-like fixed-width format fields...(are you _still_ 
listening TMW?  :) )

Don't see any code so can't comment on the error but textscan() should 
solve your problem (albeit w/ returned values in a cell array rather 
than simple 2D array of doubles).

fmt=[repmat('%*s ',1,4) repmat('%f ',1,3)];
fid=fopen('yourfile','rt');
c=textscan(fid,fmt,'headerlines',9,'collectoutput',1)
c =
     [3x3 double]
c=[c;textscan(fid,fmt,'headerlines',2,'collectoutput',1)]
c =
     [3x3 double]
     [3x3 double]

fid=fclose(fid);

c{:}
ans =
    56.0010   -0.0010    0.1370
    56.0000   -0.0010    0.1120
    56.0000   -0.0010    0.1120
ans =
    1.0e+03 *
     6.3781   -0.0000         0
     6.3781   -0.0000         0
     6.3781   -0.0000         0

Repeat as needed; you can build a loop if size of file is unknown that 
quits on feof(fid) as long as you know the spacing between groups of data.

Or, if that spacing isn't known, you can always revert to fgetl() and 
read a line at a time until you find the next Yaqw string in the header 
line.

Too bad textread() isn't as flexible to return the array directly 
instead of the cell, Steven.  :)

--
0
none1568 (7453)
3/27/2013 6:26:26 PM
On 3/27/2013 1:26 PM, dpb wrote:
> On 3/27/2013 12:41 PM, Abubakar Rehman wrote:
> ...
>
>> My text file looks like the following
>>
>> 32 Fed 2044 25:61:61
>> Asdfg-Asdfg
>>
>>
>> Data Unavailable
>>
>>
>> Yaqw (UUUUU) Qwe (321) (deg) Asdfg (321) (deg) Yxcv (321) (deg)
>> ----------------------- --------------- -----------------
>> ----------------
>> 32 Def 2022 10:00:00.040 56.001 -0.001 0.137
>> 32 Def 2022 10:00:00.060 56.000 -0.001 0.112
>> 32 Def 2022 10:00:00.080 56.000 -0.001 0.112
>>
>> Yaqw (UTCG) i (re) h (re) g (re) ------....--------- --------
>> 32 Def 2022 10:00:00.000 6378.139002 -0.000844 0.000000
>> 32 Def 2022 10:00:00.020 6378.139001 -0.000504 0.000000
>> 32 Def 2022 10:00:00.040 6378.139001 -0.000255 0.000000
>>
>>
>> I want the values 56.001, -0.001, 0.137, 6378.139002 etc.. in an array..
>>
>> I have written the follownig code but it doesn't work. It returns error
>> 'First argument must be a string'
>
> Oh, for Fortan-like fixed-width format fields...(are you _still_
> listening TMW? :) )
>
> Don't see any code so can't comment on the error but textscan() should
> solve your problem (albeit w/ returned values in a cell array rather
> than simple 2D array of doubles).
>
> fmt=[repmat('%*s ',1,4) repmat('%f ',1,3)];
> fid=fopen('yourfile','rt');
> c=textscan(fid,fmt,'headerlines',9,'collectoutput',1)
> c =
> [3x3 double]
> c=[c;textscan(fid,fmt,'headerlines',2,'collectoutput',1)]
> c =
> [3x3 double]
> [3x3 double]
>
> fid=fclose(fid);
>
> c{:}
> ans =
> 56.0010 -0.0010 0.1370
> 56.0000 -0.0010 0.1120
> 56.0000 -0.0010 0.1120
> ans =
> 1.0e+03 *
> 6.3781 -0.0000 0
> 6.3781 -0.0000 0
> 6.3781 -0.0000 0
>
> Repeat as needed; you can build a loop if size of file is unknown that
> quits on feof(fid) as long as you know the spacing between groups of data.
>
> Or, if that spacing isn't known, you can always revert to fgetl() and
> read a line at a time until you find the next Yaqw string in the header
> line.
>
> Too bad textread() isn't as flexible to return the array directly
> instead of the cell, Steven. :)

But, in this case cell2mat() is sufficient so isn't too bad...

 >> cell2mat(c)
ans =
    1.0e+03 *
     0.0560   -0.0000    0.0001
     0.0560   -0.0000    0.0001
     0.0560   -0.0000    0.0001
     6.3781   -0.0000         0
     6.3781   -0.0000         0
     6.3781   -0.0000         0
 >>

--

0
none1568 (7453)
3/27/2013 8:46:31 PM
Reply:

Similar Artilces:

How to get the value from a text filed ?
Hi all, I want to ask how can i get the value in a text field and save to database. My database is Oracle 9i and using Louts Domino 7. THx a lot Match That's kind of a vague question.... What language? @Formula, LS, Java ? You want to store a textfield from a NotesDocument to a Record in your oracle 9i db? matchsin@gmail.com schrieb: > Hi all, > I want to ask > how can i get the value in a text field and save to database. > My database is Oracle 9i and using Louts Domino 7. > > THx a lot > Match > Yes...... I am using loutsscri...

How to format a text file just like the RFC-text files?
I want to make some document go like these, what tools can help? Any help would be nice, thanks! BLIOGRAPHY ........................................... 34 APPENDIX A. EXAMPLES ............................................... 36 B. SIMPLE FIELD PARSING ................................... 40 C. DIFFERENCES FROM RFC #733 .............................. 41 D. ALPHABETICAL LISTING OF SYNTAX RULES ................... 44 August 13, 1982 - i - RFC #822 ^L Standard for ARPA Internet Text Messages PREFACE By 1977, the Arpanet employed several informal standards for the text messages (mail) sent among its host computers. It was felt necessary to codify these practices and provide for those features that seemed imminent. The result of that effort was Request for Comments (RFC) #733, "Standard for the Format of ARPA Network Text Message", by Crocker, Vittal, Pogran, and Henderson. The specification attempted to avoid major changes in existing software, while permitting several new features. The framework severely constrains document tone and appear- ance and is primarily useful for most intra-organization communi- cations and well-structured inter-organization communication. It also can be used for some types of inter-process commun...

Registry contains reference to dll instead of description text, how to call dll to get text? (values in the format @xxxx.dll,-yyy )
I have a simple program that list information of all the windows services from the registry. Now in Windows Vista and 2008 server the display name and description are not simple text strings, but a reference to a dll, see this example: The service "Application Experience": [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\AeLookupSvc] "DisplayName"="@%SystemRoot%\\system32\\aelupsvc.dll,-1" "Description"="@%SystemRoot%\\system32\\aelupsvc.dll,-2" Can anyone explain to me what this mean? I assume I have to call this DLL to get the informat...

convert any video file format into avi file format in matlab
hai, Now i doing my video project in Image Processing,my query is how convert other video file format into (.avi) file formate. (because only avi file format video or movie read by matlab function) for example: how convert (.flv) format into (.avi) Help (mmreader) function is not found I use Flash to Video Encoder Pro to convert flv and swf to another video formats, avi as well) Simple program) ...

Get value from a text file (newbie)
Hello, I have a question about the possibility to read some informations in a text file. For example, I have a entity 'scaler'. Can I do something like architecture Behavioral of scaler0 is component scaler generic ( ???) port ( clr : in std_logic; clk : in std_logic; d : in std_logic_vector(15 downto 0); q : out std_logic_vector(15 downto 0)); end component; begin scaler0_c : scaler generic map ( ??? => 'filename of file containing initialisation data') port map (...... ...... end Behavioral; Thank you in ad...

getting values from a text file (newby)
Hi, My foo.txt file contains the following: 1,"house","2,5" 2,"table","6,7" 3,"chair","-4,5" .... as seen with notepad. This file was created with the OpenOffice Calc spreadsheet, but since I use comma as the decimal separator for numbers, the last value in each line appears sorrounded by quotes. I would like to obtain: [[1,"house",2.5], [2,"table",6.7], [3,"chair",-4.5]] in order to process the content of the file. However, so far, I have not obtained the desired result. I started testing with (o...

Reading a text file into a Matlab Matrix
Hello there, I have a text file that contains the following; word11 word12 word13 word14 word21 word22 word23 word24 word31 word32 word33 word34 I want to read it into a 3x4 matrix (each word in a separate cell) I tried to use; data = textread('fileName.txt', '%s', 'delimiter', '\n') - puts each line in one cell data = textread('fileName.txt', '%s', 'delimiter', ' ') - puts each word in one cell but in a 12x1 matrix/array [col1 col2 col3 col4] = textread('tE.txt', '%s %s %s %s', 'delimit...

import text file with hex values to matlab
Hi guys, I am trying a text file containing many lines of data in hexadecimal format. The data is in the format A = |22 43 FF A2 ...| |22 42 FA A1 ...| I have tried load command, textscan, fscan, textread but I cannot get a matrix. I can get the values organized in a matrix like manner but then I cannot use the command hex2dec because the all matrix is seen as a big vector. I had this: EDU>> fid =fopen('test.txt'); EDU>> A = fscanf(fid,'%c') A = 10 30 de ff 23 12 00 00 34 67 48 cc EDU>> fclose(fid); EDU>> a = A; EDU>> a a = 10 30 d...

Standard Text Format for Floating Point Values?
I have noticed a great deal of variance between various run time libraries for C++ compilers in how floating point values (floats and doubles) get formatted when they represent "invalid" values such as plus or minus infinity or not a number. I work with applications where the presentation of such data is rather important and find myself frustrated that, even with the same library, I cannot write out such a value as text to a stream and expect it to be read from that stream as the same value. My question is whether there is any standard for describing these type of values as text. ...

Change the format of text file generated from MATLAB code
Hello I am generating a text file using MATLAB which looks something like this 6.9905301e+001 6.9193786e+001 7.0975918e+001 7.5127181e+001 7.7340259e+001 8.0573000e+001 8.3738719e+001 8.1974246e+001 7.9527688e+001 8.0201600e+001 7.9433180e+001 7.9606963e+001 7.8440122e+001 7.7089076e+001 7.7316589e+001 7.8372644e+001 8.1083666e+001 8.2169213e+001 8.0140552e+001 7.9732129e+001 I want these numbers in the format of decimals only, no powers. For e.g. I want 699.053 rather than 6.9905301e+001 and so on. Is there any way of doing this using MATLAB? Thank you in advanc...

How can I get the value from text file from a specific line and column?
Hi there, How can I get the value from text file from a specific line and column in MATLAB? For example, Hello.txt 00001 38 49 50 61 72 00002 12 23 45 56 00003 12 45 89 32 98 78 00004 23 45 78 00005 12 45 89 98 00006 22 1 2 3 I want a value from line 3 column 4 which is 89 to be a variable in workspace. What should I do? And also for a whole line and whole column too. Thx This is an example only, actually my data is bigger than this. The number of data in each line, is not equal. Hi, it's quiet easy if the text file contains only numeric data : [A]=textread('hello.txt',...

Conversion of Matlab tool (Simulink model file format (or) .mdl file format (or) S-functions) to C-language
i did my project in "image processing based one"using matlab simulink tool.My project title is "Motion Estimation and Visualization In Real-Time Image Sequences".Can anybody help for the conversion of matlab simulink tool (Simulink model file (or) .mdl file format (or) S-functions)to C? and also for M-file to C? ...

how to open a text file containing both float and strings and select the required values
The data file is saved by file name 'xyz.txt' containing : ********* Header Information for Record 1 ====== LINE 1 255 9 2005 7 13 7 0 5 2500 25000 1.13312 31.5811 31.1895 32.3667 0 0.186697 200 60 1 ========== LINE 2 --------- Total Number of Bins = 2001 =========== LINE 3 1 0.178756 ======LINE 4 and so on 2 0.178756 3 12.4982 4 1.43867 5 1.26344 6 1.05756 7 0.893836 8 0.888867 9 0.928455 10 1.06719 11 1.20537 12 1.43773 13 1.66256 14 2.3405 15 1.61992 Now (1) I want to know how to open a file of this kind of data ...

Import Text File (non delimiter) to matlab with deimiter format and convert to Excel
Hi.. Have a great day ahead guys! I have a question that, I have download 1 rainfall data int Text file *.txt= it included texts, heading, bottom text, and data also some of spaces line= between data. When I import the file into the Matlab, The matlab could not defined each c= ells included column, and rows (non delimiter) I have did like, convert text file to Excel, and remove the cols and rows v= ery easily and save with another files. But my data is up to 846000 data se= t ~ 24h x 30days x 12month x 20 years which combined many different files = for each data. SO it will difficult to make manual converting like I did. My adviser told me that there are Matlab CODE could do it well. Does anyone= can help me this problem? Thanks On Friday, November 15, 2013 6:03:20 PM UTC+13, QU=C3=82N H=E1=BB=92NG wrot= e: > Hi.. >=20 > Have a great day ahead guys! >=20 > I have a question that, I have download 1 rainfall data int Text file *.t= xt it included texts, heading, bottom text, and data also some of spaces li= ne between data. >=20 > When I import the file into the Matlab, The matlab could not defined each= cells included column, and rows (non delimiter) >=20 > I have did like, convert text file to Excel, and remove the cols and rows= very easily and save with another files. But my data is up to 846000 data = set ~ 24h x 30days x 12month x 20 years which combined many different file= s for each data. SO it will diffic...

batch file processing of text files in matlab
Hi, Can somebody guide me if we can do batch processing on text files in matlab..if yes, any guidelines will be appreciated.. Cordially, safee ...

Select and get text from Edit text filed
Hi, I need to make a simple text editor in matlab gui. I want is the user to be able to select part of the text he had typed and make the fontweight bold. I don't know how to get the selected text. Can you give me some clues? Thanks. ...

i made a gui in matlab now i want to get a variable's value(that is a 3 by 3 matrix) defined in a script file(named nn2)
i made a gui in matlab now i want to get a variable's value(that is a 3 by 3 matrix) defined in a script file(named nn2) manish sahu <manish.comp05@gmail.com> wrote in message <ad202390-c536-473e-8496- 664d9b45e403@b5g2000pri.googlegroups.com>... > i made a gui in matlab now i want to get a variable's value(that is a > 3 by 3 matrix) defined in a script file(named nn2) well, run the script so the variable is in the workspace, then use it. ...

Why do I get a ? in front of text when open Unicode text file
Hello I have a file which I created in Notepad on Windows. I pasted some text from the clipboard into the file and when I saved I chose in the Save As options Unicode. But when I attempt to open the file like this: typedef std::basic_string<TCHAR> tstring tstring str; DWORD dwSize = GetFileSize (hFile, &fs) ; DWORD dwBytesRead; TCHAR* szRead = new TCHAR[(dwSize + 1)]; BOOL bSuccess = ReadFile(hFile, szRead, dwSize, &dwBytesRead, NULL) ; CloseHandle(hFile); str = szRead; delete [] szRead; There is a ? as the first character of the string in szR...

Convert UNIX formated text files to DOS formated?
I have about 150 unix formated text files that I would like to convert to dos formated. I am guessing that I loop though each file in the directory, read each line and conver the last character, then save to a file with the same name in another directory. I am not really sure what I convert the last charactor to. walterbyrd schrieb: > I have about 150 unix formated text files that I would like to convert > to dos formated. > > I am guessing that I loop though each file in the directory, read each > line and conver the last character, then save to a file with the same > na...

i made a gui in matlab now i want to get a variable's value(that is a 3 by 3 matrix) defined in a script file(named nn2) #2
i made a gui in matlab now i want to get a variable's value(that is a 3 by 3 matrix) defined in a script file(named nn2) manish sahu <manish.comp05@gmail.com> wrote in message <66e1285d-5710-4f8b-90fc-b4a8d732dd30@h1g2000prh.googlegroups.com>... > i made a gui in matlab now i want to get a variable's value(that is a > 3 by 3 matrix) defined in a script file(named nn2) U can use fread command to red and then converting string to numerical value, else u can save the data into a mat file and read back. Is it what u are looking for?? Ashwini ...

Reading Text File, Text Scrolling and erase line from a text file
Hi , How can I Reading Text File, then Text Scrolling by means of keys "page UP" "page Down" and erase a specific line from a text file , when press "F2" key? Best Regards, Lidia from Poland -- ========================================= Pozdrawiam Lidiaa Lidiaa schrieb: > Hi , > > How can I Reading Text File, then Text Scrolling by means of > keys "page UP" "page Down" and erase a specific line from a text > file , when press "F2" key? > > ...

Trying to Read text files, get some files that show up as empty
As I said above some I am attempting to read data from a number of text files and then parse it. But as I am attempting to acquire the index of a delimiter in the files, some show up as blank- when in fact that word exists in them. I've considered formatting info as a problem, but when I looked into the fscanf stream, they are not saved, so this can't be it. Is this an issue with the fxn -regexp itself? I tried strfind and got the same issue. I am missing something can't figure what it is. Any help is greatly appreciated. Thanks, Dan Here is my code::: %% Get Author Data fro...

Write Property Bag to Text file in Text format, not binary
Hi all I know that I can persist an object's data using the Property Bag in VB6 and MSDN includes the code sample listed below. However what I want to do is save to the text file in PLAIN TEXT Format, *not* as binary. I want to save the file so that it is human readable in the format: name of the property to save; the value to save (mInterestRate). However all the examples that I have found only show how to output the object as binary. Is it possible to write as plain text? Private pb As PropertyBag ' Declare a PropertyBag object. Private LoanObject As Loan ' Declare a ...

how to find a pattern in a file and get output in another file in different format
Hello members, I am very new in Java programming, I want some help from you. Actually I have one file named as "list01.txt" in which the content is in following format Record # 1 Au: Kuzur, A D Au: Dito, Bolte Ti: Elements of semantic web. Pu: Nasadac Pl: New Delhi Record # 2 Au: Kumar, Vinit Ti: Learning how to learn. Pu: Pooja Pl: Bangalore Record # 3 Au: Pandey, Anand K Ti: Emerging minds. Pu: Lakhotia Pl: Varanasi what I am trying to do is to get output in some new files in following format In file record1.txt <author> Kuzur, A D</author> <author>Dito,...

Web resources about - Getting float values from a formatted text file - comp.soft-sys.matlab

Formatted text - Wikipedia, the free encyclopedia
Formatted text cannot rightly be identified with binary files or be distinct from ASCII text. This is because formatted text is not necessarily ...

Received a badly formatted email on your mobile? 75 percent of you will delete it
A survey by Constant Contact shows that mobile devices are more important than ever, particularly to those under the age of 30. The study reveals ...

Quickly view formatted PDFs in your search results
Google search results sometimes include documents that were not originally formatted to be viewed in a web browser, such as PDFs. In the past, ...

Now in Google search results: Formatted PDFs
Google has launched a new search option called Quick View that allows users to open formatted PDF filesnot just HTML viewing of documentsfrom ...

Proxy ports showing formatted text in Mountain Lion
An interface bug in the OS X Network system preferences shows unconventional port string formats, but does not affect OS X performance.

It’s Markdown, no, PowerShell. Wait its Markdown formatted PowerShell.
... "Current DateTime is = $([System.DateTime]::Now)" ### Escape characters with the ` (back-tick) "Escape a quotation `"This is quoted`"." Formatted ...

Exploit can control older Macs even after they're formatted
Exploit can control older Macs even after they're formatted

HBO cancels 'In Treatment' 'as previously formatted'
HBO just made it official: In Treatment will not return for a fourth season. The psychotherapist drama won plenty of critical acclaim and Emmy ...

FAA GPS data formatted for your use
[Michael] posted up-to-date GPS data sets in the GPX format . These data sets are an alternative to paid updates. Since GPX is a published standard ...

Converting Mac-formatted iPod to Windows - iLounge Article
Q: In reading your FAQ and previous columns, I see that it is possible to use a Mac-formatted iPod on a Windows PC through the use of a third-party ...

Resources last updated: 3/10/2016 7:13:34 AM