Marco Atzeri <address@hidden> writes:
On 9/23/2011 3:13 PM, 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
[cut]
1983;4036,7
1984;4249,6
Thanks,
Sebastián.
sed is your friend, in two step
sed -e "s/,/./" -e "s/;/,/" old_file > new_file
sed 's/,/./; s/;/,/' old > new
does the trick with less writing, although it does look like my cat
danced on the keyboard.
--
Here is an octave-only solution:
function X = csvread_ns(file)
fid=fopen(file);
X=[];
while ((line=fgetl(fid)) && !(line == -1))
line=strrep(line,",",".");
line=strrep(line,";",",");
x=sscanf(line,"%i,%f");
X=[X,x];
endwhile
fclose(fid);
endfunction
octave> > > > > > > > > > > octave> system("cat /tmp/octave.txt");
1953;1453,6
1954;1480,1
1955;1576,4
1956;1621,5
1983;4036,7
1984;4249,6
octave> csvread_ns("/tmp/octave.txt")
ans =
1953.0 1954.0 1955.0 1956.0 1983.0 1984.0
1453.6 1480.1 1576.4 1621.5 4036.7 4249.6
_______________________________________________
Help-octave mailing list
address@hidden
https://mailman.cae.wisc.edu/listinfo/help-octave