how to save a text file

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

how to save a text file

Kasius Klej
I'm trying to modify a text file and having trouble with what seems to be an
easy task. I'm new to Octave and the documentation for me is all Greek for
now. Perhaps someone could help me? I gather this is an easy question.

#this works fine for me
[A]=textread('input.csv', '%s');
A= strrep(A,",",";");

#this is where trouble begin, this is where I get salad
save ("test.txt", "A");

#or this, this is where I get error message
save ("-ascii", "test.txt", "A");

error: octave_base_value::matrix_value(): wrong type argument 'cell'
warning: save: unable to save A in ASCII format






--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: how to save a text file

Andreas Weber-6
Am 05.03.2018 um 23:42 schrieb Kasius Klej:
> I'm trying to modify a text file and having trouble with what seems to be an
> easy task. I'm new to Octave and the documentation for me is all Greek for
> now. Perhaps someone could help me? I gather this is an easy question.
>
> #this works fine for me
> [A]=textread('input.csv', '%s');
> A= strrep(A,",",";");

This sounds like an XY-Problem. What do you really want to do?

If you want to replace "," with ";" in a file you would use tr or sed on
unix like systems. If you want to do this in GNU Octave I would do:

A = fileread ("input.csv");
A = strrep(A, ",", ";");
fid = fopen ("out.csv", "w");
fputs (fid, A);
fclose (fid);


But keep in mind that you can change the delimiter in dlmread (just in
case your actual question is how to read a CSV)

-- Andy


-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: how to save a text file

Kasius Klej
Thanks, Andreas, this worked perfectly.

If you are wondering why I would want to replace commas for semicolons in a
text file, it's because I have a funny Excel, I live in a country where
commas serve a different purpose (they're used for decimal numbers).

I'm doing this for my neighbor who wants to automate some tasks in his Excel
tax scheme. This step helped us get some data into Excel where we will
continue with Vlookup and such. I believe Vlookup could also be done in
Octave with clever matrix manipulation, but Excel should handle it from here
on, with macros.



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------