Path: news.mathworks.com!not-for-mail
From: "Ashish Uthama" <first.last@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Textread
Date: Wed, 01 Jul 2009 15:26:02 -0400
Organization: TMW
Lines: 72
Message-ID: <op.uwellojea5ziv5@uthamaa.dhcp.mathworks.com>
References: <h2favd$6b6$1@fred.mathworks.com>
 <op.uwd76lf8a5ziv5@uthamaa.dhcp.mathworks.com>
 <h2gbad$3rj$1@fred.mathworks.com>
NNTP-Posting-Host: uthamaa.dhcp.mathworks.com
Mime-Version: 1.0
Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-15
Content-Transfer-Encoding: 7bit
X-Trace: fred.mathworks.com 1246476362 10261 172.31.57.126 (1 Jul 2009 19:26:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 1 Jul 2009 19:26:02 +0000 (UTC)
User-Agent: Opera Mail/9.63 (Win32)
Xref: news.mathworks.com comp.soft-sys.matlab:552149


On Wed, 01 Jul 2009 14:53:01 -0400, Jesper Lauridsen  
<jesperholst_5@hotmail.com> wrote:

> "Ashish Uthama" <first.last@mathworks.com> wrote in message  
> <op.uwd76lf8a5ziv5@uthamaa.dhcp.mathworks.com>...
>> On Wed, 01 Jul 2009 05:41:02 -0400, Jesper Lauridsen
>> <jesperholst_5@hotmail.com> wrote:
>>
>> > I have a text file with the following data:
>> >
>> > 72008,16193    	-0,01    	0,02    	0,015
>> > 72008,16375    	-0,029    	-0,034    	-0,034
>> > 72008,16406    	-0,02    	-0,054    	-0,059
>> > 72008,16437    	-0,024    	-0,039    	-0,039
>> > 72008,16467    	0,02    	-0,044    	-0,044
>> > 72008,16498    	-0,005    	-0,005    	-0,005
>> > 72008,16529    	0,034    	0,015    	0,01
>> > 72008,1656    	0,01    	0,034    	0,034
>> > 72008,16591    	0,029    	0,01    	0,01
>> >
>> > I want to load the data in Matlab and replace the comma with dots.  
>> Can I
>> > use the textread function and load it into an cell array and replace  
>> the
>> > commas with dots or how do I do it?
>>
>> That would be one approach. Did you try it?
>> (FOPEN, TEXTSCAN, STRREP, STR2DOUBLE)
>>
> Hey everybody. Thank you very much for all your comments. The text file  
> I have contain 4 columns and 800000 rows each. I have to replace the  
> commas with dots in all rows and columns. Therefor I would prefer if it  
> is possible til replace the commas, without writing a new file as Rune  
> surgest.
>
> I tried:
>
>>> data = importdata('data_in.dat');
>>> dlmwrite('data_out.dat',data,'.')
> ??? Error using ==> dlmwrite
> The input cell array can not be converted to a matrix.
>
> The name of the data file i loaded was data_in.dat

Did you inspect the data you get from IMPORTDATA. (I would recommend using  
FOPEN, TEXTSCAN)

Is it a cell array of strings? If so:

STRREP can be used to replace , with . in strings.
STR2DOUBLE will then convert it to a matrix.

>> strData={ '2,3'  '4,5' ; '6,45' '-0,3'}

strData =

     '2,3'     '4,5'
     '6,45'    '-0,3'

>> strData={ '2,3'  '4,5' ; '6,45' '-0,3'};
>> numData=str2double(strrep(strData,',','.'))

numData =

           2.3          4.5
          6.45         -0.3

>> whos
   Name         Size            Bytes  Class     Attributes

   numData      2x2                32  double
   strData      2x2               268  cell