Thread Subject: can not read float numbers from a txt file.

Subject: can not read float numbers from a txt file.

From: Leblead Sweid

Date: 13 Aug, 2009 09:25:17

Message: 1 of 4

Hi everybody,

i am trying to read float numbers from a text file, but it worked only if i assume the float numbers as string .To be more clear, i have tried that:

data=textscan(fid,'%*s%s%s%s%s%s%s%s%s%s%s%s%s%s','delimiter', ';')

to read that file

00:00:19,968;8,02;8,44;8,30;7,79;8,19;7,96;9,80;9,44;15,42;16,35;13,40;13,19;8,16;
00:00:19,972;8,00;8,49;8,35;7,86;8,24;7,85;9,72;9,33;15,01;16,04;13,41;13,43;8,05;
00:00:19,976;7,91;8,40;8,18;7,89;8,13;7,96;9,78;9,49;15,14;16,36;13,41;13,31;8,02;
00:00:19,980;7,95;8,45;8,29;7,84;8,19;8,02;9,92;9,53;15,00;16,49;13,28;13,34;8,26;

so when i used:

data=textscan(fid,'%n%n%n%n%n%n%n%n%n%n%n%n%n%n','delimiter', ';')

i got only two arrays instead of 14 arrays and in the two arrays there are only numbers with nothing after the comma.

thanks .

Subject: can not read float numbers from a txt file.

From: Rune Allnor

Date: 13 Aug, 2009 10:40:25

Message: 2 of 4

On 13 Aug, 11:25, "Leblead Sweid" <bhann...@live.com> wrote:
> Hi everybody,
>
> i am trying to read float numbers from a text file, but it worked only if i assume the float numbers as string .To be more clear, i have tried that:
>
> data=textscan(fid,'%*s%s%s%s%s%s%s%s%s%s%s%s%s%s','delimiter', ';')
>
> to read that file
>
> 00:00:19,968;8,02;8,44;8,30;7,79;8,19;7,96;9,80;9,44;15,42;16,35;13,40;13,1­9;8,16;

You are using a locale where the decimal mark is comma
rather than dot. You need to change this before you
attempt to convert from text to numbers.

If you read the lines from the file yourself (as opposed
to using some canned routine), use

s = sttrep(s,',','.');

You might also have a problem with the penultimate column,
which contains 13,1-9. It is not at all obvious that this
will be accepted, or if so, converted correctly:

>> sscanf('13.1-9','%f')

ans =

   13.1000
   -9.0000

>> str2num('13.1-9')

ans =

    4.1000

Rune

Subject: can not read float numbers from a txt file.

From: Rune Allnor

Date: 13 Aug, 2009 10:41:51

Message: 3 of 4

On 13 Aug, 12:40, Rune Allnor <all...@tele.ntnu.no> wrote:

> > 00:00:19,968;8,02;8,44;8,30;7,79;8,19;7,96;9,80;9,44;15,42;16,35;13,40;13,1­­9;8,16;

> You might also have a problem with the penultimate column,
> which contains 13,1-9.

Sorry, something bad happened when I cut'n pasted
your data to matlab.

Rune

Subject: can not read float numbers from a txt file.

From: Andres

Date: 13 Aug, 2009 19:36:03

Message: 4 of 4

Hi,
try

data = txt2mat(filename.txt);

with txt2mat from the file exchange ( http://www.mathworks.de/matlabcentral/fileexchange/18430 ).

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
textscan Sprinceana 22 Aug, 2009 05:03:11
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com