help-octave
[Top][All Lists]
Advanced

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

Re: exporting arrays to C


From: Andrey Romanenko
Subject: Re: exporting arrays to C
Date: Wed, 10 May 2006 23:13:20 +0100
User-agent: KMail/1.9.1

Hi!

On Wednesday 10 May 2006 21:40, 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.
[]
> What's the least painful way to do this?

Will something along the following lines work?:

a=randn(10,5);
fp=fopen("mat.h", "w");
fprintf(fp, "double *mat={ ");
for i=1:size(a,1)
   fprintf(fp, "{ %f", a(i,1));
   for j=2:size(a,2)
      fprintf(fp,", %f", a(i,j));
   endfor;
   fprintf(fp, "},\n");
endfor;
fprintf(fp, "};\n");
fclose(fp);

warning: untested code :)

Andrey


reply via email to

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