help-octave
[Top][All Lists]
Advanced

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

Re: exporting arrays to C


From: Bill Denney
Subject: Re: exporting arrays to C
Date: Wed, 10 May 2006 17:20:57 -0400 (EDT)

On Wed, 10 May 2006, NZG wrote:

I've got an 8k array of data in Octave that I need to export as a C matrix to make a lookup table. Currently I'm using "save" in conjunction with a normal text editor "replace" to add commas and brackets. This works ok, but doesn't break the array into multiple lines, it's just one huge line, which is harder to break with a "replace".

What's the least painful way to do this?

It depends exactly what you want to do. If you want to keep exporting it as a text file and just make the exporting easier (i.e. not opening it with a text editor), you can look into either csvwrite or dlmwrite (both in octave-forge.

If those don't do what you're wanting, you can try something like

matrix = 1:10;
filename = "myfile.txt";

fid = fopen (filename);
fprintf (fid, "%g," matrix);
fprintf (fid, "\n");
fclose (fid);

(I didn't actually test the code, but something similar should work.)

There are other methods of writing to files and you can also directly link your C code to octave (other people are more expert in that, so they would be better to ask about it).

Bill

--
The decision doesn't have to be logical, it is unanimous.
  -- unknown



reply via email to

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