help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: file where sep decimals is comma


From: Przemek Klosowski
Subject: Re: file where sep decimals is comma
Date: Fri, 23 Sep 2011 14:16:11 -0400
User-agent: Mozilla/5.0 (X11; Linux i686; rv:6.0.2) Gecko/20110906 Thunderbird/6.0.2

On 09/23/2011 09:13 AM, Sebastian Kruk wrote:
Hi, I have a csv file where sep is ";" and I have "," as decimal point.

How I can import directly in Octave?

An example:

1953;1453,6
1954;1480,1
1955;1576,4
1956;1621,5
1957;1655,3

One way is to do it entirely within Octave, by reading the file as-is, doing string substitution of your delimiters, and reading back the resulting string. Here's the Octave code, assuming that your file is called "data":

a=fread(fopen("data"));
a(a==",")=".";
a(a==";")=",";
b=reshape(sscanf(strvcat(a'),"%f,%f"),2,32)';

an alternative might be to use an external utility, e.g. using Perl:

system("perl -pe 's/,/./g;s/;/,/g' data > b")
load b

I suspect that there are less awkward/quirky ways of implementing the pure-Octave version---can anyone suggest something nicer looking?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]