DSPRelated.com
Forums

Matlab arrays to C code

Started by Pasi March 16, 2005
Hi!

How can I c+p matlab arrays (very large) to c code? Can I write it to 
some file in matlab? Like:

in matlab
---
 >> S=[1 2 3 4 5;2 3 4 5 6]

S =

      1     2     3     4     5
      2     3     4     5     6
---

In c:
---
int S[2][5] ={
{1, 2, 3, 4, 5},
{2, 3, 4, 5, 6}
};
---

If I c+p directly this text from matlab to c code, I have very much to 
the doing.
Pasi wrote:

> Hi! > > How can I c+p matlab arrays (very large) to c code? Can I write it to > some file in matlab? Like: > > in matlab > --- > >> S=[1 2 3 4 5;2 3 4 5 6] > > S = > > 1 2 3 4 5 > 2 3 4 5 6 > --- > > In c: > --- > int S[2][5] ={ > {1, 2, 3, 4, 5}, > {2, 3, 4, 5, 6} > }; > --- > > If I c+p directly this text from matlab to c code, I have very much to > the doing.
"c+p"? Look to see what kind of formatted printing facilities Matlab has -- it'll probably be named "printf" or "fprintf" and you should be able to output in whatever language you want. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
Tim Wescott wrote:
> Pasi wrote: > >> Hi! >> >> How can I c+p matlab arrays (very large) to c code? Can I write it to >> some file in matlab? Like: >> >> in matlab >> --- >> >> S=[1 2 3 4 5;2 3 4 5 6] >> >> S = >> >> 1 2 3 4 5 >> 2 3 4 5 6 >> --- >> >> In c: >> --- >> int S[2][5] ={ >> {1, 2, 3, 4, 5}, >> {2, 3, 4, 5, 6} >> }; >> --- >> >> If I c+p directly this text from matlab to c code, I have very much to >> the doing. > > > "c+p"? >
Copy and paste.
"Pasi" <pasi@pa.si> wrote in message news:d1a7pr$6fq$2@plaza.suomi.net...
> Hi! > > How can I c+p matlab arrays (very large) to c code? Can I write it to > some file in matlab? Like:
Pray tell what 'c+p' is?
> in matlab > --- > >> S=[1 2 3 4 5;2 3 4 5 6] > > S = > > 1 2 3 4 5 > 2 3 4 5 6 > --- > > In c: > --- > int S[2][5] ={ > {1, 2, 3, 4, 5}, > {2, 3, 4, 5, 6} > }; > --- > > If I c+p directly this text from matlab to c code, I have very much to > the doing.
Well, you can open a file pointer in matlab, use fprintf (and its variants) to write to the file in a form that is suitable for C. Look up fopen, fprintf in the matlab help files for details. You should also be asking this in the matlab newsgroup (perhaps only there). comp.soft-sys.matlab Cheers Bhaskar
As Tim wrote, fprintf is the function to use. You'd had to write your own 
script, though (but that's not too complicated)

-- 
------------------------------
Jaime Andr&#4294967295;s Aranguren Cardona
jaac@sanjaac.com
SanJaaC Electronics
Soluciones en DSP
www.sanjaac.com


"Pasi" <pasi@pa.si> escribi&#4294967295; en el mensaje 
news:d1a8v5$7n9$1@plaza.suomi.net...
> Tim Wescott wrote: >> Pasi wrote: >> >>> Hi! >>> >>> How can I c+p matlab arrays (very large) to c code? Can I write it to >>> some file in matlab? Like: >>> >>> in matlab >>> --- >>> >> S=[1 2 3 4 5;2 3 4 5 6] >>> >>> S = >>> >>> 1 2 3 4 5 >>> 2 3 4 5 6 >>> --- >>> >>> In c: >>> --- >>> int S[2][5] ={ >>> {1, 2, 3, 4, 5}, >>> {2, 3, 4, 5, 6} >>> }; >>> --- >>> >>> If I c+p directly this text from matlab to c code, I have very much to >>> the doing. >> >> >> "c+p"? >> > > Copy and paste.