Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

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

No tags are associated with this thread.

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.

Contact us