Thread Subject: Decimal Separator

Subject: Decimal Separator

From: Ellen Arens

Date: 21 Nov, 2008 16:49:03

Message: 1 of 3

How can I import numeric data that uses a comma as a decimal separator? For example, a table of 640 by 480 numberic valves.

Subject: Decimal Separator

From: Andres

Date: 21 Nov, 2008 20:47:02

Message: 2 of 3

"Ellen Arens" <ellen.e.arens@nasa.gov> wrote in message <gg6opu$1i2$1@fred.mathworks.com>...
> How can I import numeric data that uses a comma as a decimal separator? For example, a table of 640 by 480 numberic valves.

You want to import the table from an ascii file?
Try out txt2mat from the matlab central file exchange. If the file structure is not too weird, just

A=txt2mat('myfile.txt')

will do.
Hth
Andres

Subject: Decimal Separator

From: Rune Allnor

Date: 21 Nov, 2008 23:41:27

Message: 3 of 3

On 21 Nov, 17:49, "Ellen Arens" <ellen.e.ar...@nasa.gov> wrote:
> How can I import numeric data that uses a comma as a decimal separator? =
=A0For example, a table of 640 by 480 numberic valves.

The general idea would be to read a full line, replace
commas by dots and then convert to numbers. Something
like (not tested!):

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fid =3D fopen('file.txt');
A =3D[];
while(~feof(fid))
    s =3D fgetl(fid); % Read line from file
    cidx =3D find(s=3D=3D','); % Find all commas...
    s(cidx)=3D'.'; % ...and replace with dots
    a=3Dsscanf('%f',s,inf); % Read in as numbers
    A =3D [A;a']; % Append to result matrix
end
fclose(fid);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Rune

Tags for this Thread

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.

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