help-octave
[Top][All Lists]
Advanced

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

RE: csvwrite text


From: William Krekeler
Subject: RE: csvwrite text
Date: Wed, 30 Mar 2011 15:36:29 +0000

-----Original Message-----
From: address@hidden [mailto:address@hidden On Behalf Of Philip Nienhuis
Sent: Wednesday, March 30, 2011 10:33 AM
To: address@hidden
Subject: Re: csvwrite text


senator wrote:
> 
> I am trying to use csvwrite and i have it working for writing a matrix of
> numbers. However, I need to output a field of text on the first row and
> then write the matrix of numbers from the second row on. So right now I am
> trying to csvwrite text into the first couple columns of the top row. I
> found that if I use these brackets [...]  I can get all the text to write,
> but Octave will put one letter in each cell of the top row rather than
> what I put in '....' per cell. I have tried many different combinations,
> but no luck so far.
> 
> is there a way I can do something like this:
> a={'time','day','temp'}
> csvwrite('myfile.csv',a);
> 

No....



> if I can do the above my plan is then to csvwrite my matrix of numbers
> starting on row 2.
> Can someone advise me the best course of action?
> 
> 
> Also, this is what sourceforge.net says for csvwrite:
> 
> Function File: x = csvwrite (filename, x)
> Write the matrix x to a file. 
> 

A bit obscure, but it says "matrix", not "cell array".
The relevant difference here is that a matrix only contains numbers, and a
cell array can contain a mixture of numbers, text strings, etc. 
(dlmwrite seems to be able to process either character arrays or numerical
arrays. A character array contains just one character per "cell", so that's
why you got just one char per cell.)



> This function is equivalent to 
>           dlmwrite (filename, x, ",", ...)
> See also: dlmread dlmwrite csvread 
> 

As you run octave-3.2.4 on Windows, obviously (hopefully) using the windows
binary from Sourceforge (see recent posts above for link), why don't you
just reinstall Octave and be sure to choose the "windows", "java" and "io"
packages from octave-forge options. 
Then you can easily write your cell array a using:
   xlswrite (, a)
to an Excel file

(If you also chose the java package you don't even need to have MS-Excel
installed)

Other options involve patching (or letting someone knowledgeable patch)
csvwrite.m so that it accepts cell arrays (hmmmm.... and patch csvread to do
the reverse). Easily done at first thought, even at first looks (I just had
a peek at dlmwrite.m which does the actual work), but the necessary input
checks are probably 90 % of the work.... (maybe, someday, I'll have a throw
at it....)

Philip


--
View this message in context: 
http://octave.1599824.n4.nabble.com/csvwrite-text-tp3418132p3418425.html
Sent from the Octave - General mailing list archive at Nabble.com.
_______________________________________________
Help-octave mailing list
address@hidden
https://mailman.cae.wisc.edu/listinfo/help-octave


But you could write your own using fopen, fwrite or fprintf, and fclose. just 
loop on the write statement to output the information you want printed in the 
format of your choosing.

Bill


reply via email to

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