f



Replacing ',' with '.'

Hello,

I have a huge amount of numbers in a .txt file. The numbers are in the form 2,43252e+1. I need to replace the , with . How should I do this? I'd prefer some import method that does this during the import procedure.

-Janne
0
snaques (2)
10/4/2006 9:57:48 AM
comp.soft-sys.matlab 211266 articles. 18 followers. lunamoonmoon (258) is leader. Post Follow

4 Replies
1334 Views

Similar Articles

[PageSpeed] 52

Hi,

I guess you import the data as text and convert it then to numbers.
Try 'strrep' before you convert the text to numbers.

Tobias

Jake the Snake schrieb:
> Hello,
> 
> I have a huge amount of numbers in a .txt file. The numbers are in the form 2,43252e+1. I need to replace the , with . How should I do this? I'd prefer some import method that does this during the import procedure.
> 
> -Janne
0
tc-nwsl-03 (27)
10/5/2006 9:42:52 AM
Jake the Snake skrev:
> Hello,
>
> I have a huge amount of numbers in a .txt file. The numbers are in the form 2,43252e+1. I need to replace the , with . How should I do this? I'd prefer some import method that does this during the import procedure.
>
> -Janne

If you have one file and the decimal separators are the only commas
in the file, load the file into some ascii text editor (notepad, emacs,

maube even matlab's editor) and use the "find..replace" function.

It will take you 2 seconds to do and the computer may be running
for a couple of minutes. Don't spend more of YOUR time (the computer
run-time is irrelevant if this truly is a one-off incident) with this
than
necessary, unless there are other complicating factors or you expect
or fear that this number format will occur again.

Rune

0
allnor (8509)
10/5/2006 10:10:44 AM
On Thu, 05 Oct 2006 03:10:44 -0700, Rune Allnor wrote:

> Jake the Snake skrev:
>> Hello,
>>
>> I have a huge amount of numbers in a .txt file. The numbers are in the form 2,43252e+1. I need to replace the , with . How should I do this? I'd prefer some import method that does this during the import procedure.
>>
>> -Janne
> 
> If you have one file and the decimal separators are the only commas
> in the file, load the file into some ascii text editor (notepad, emacs,
> 
> maube even matlab's editor) and use the "find..replace" function.
> 
> It will take you 2 seconds to do and the computer may be running
> for a couple of minutes. Don't spend more of YOUR time (the computer
> run-time is irrelevant if this truly is a one-off incident) with this
> than
> necessary, unless there are other complicating factors or you expect
> or fear that this number format will occur again.
> 
> Rune



or if you are on linux/unix/mac and this is not a single incident, then
you might want to read up on a tool called awk.


michael
0
10/5/2006 12:34:41 PM
In article <4524edd1$1@news1.ethz.ch>,
Michael Wild <themiwi.REMOVE.THIS@student.ethz.ch> wrote:
>or if you are on linux/unix/mac and this is not a single incident, then
>you might want to read up on a tool called awk.

Or, even simpler, tr(1).

If the poster really wants to do it in Matlab, he could try
something like:

  tname = tempname;
  fidi=fopen(fname, 'r');
  fido=fopen(tname, 'w');
  while feof(fidi) == 0
      line = fgetl(fidi);
      line = strrep(line, ',', '.');
      fprintf(fido, '%s\n', line);
  end
  fclose(fidi);
  fclose(fido);
  m = dlmread(tname);  % or other 'import' of choice
  delete(tname);

Not the most efficient method, but easy to understand.  

Francis
0
fburton (444)
10/5/2006 7:23:01 PM
Reply: