help-octave
[Top][All Lists]
Advanced

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

Re: Write a cell array to a textfile


From: Ben Abbott
Subject: Re: Write a cell array to a textfile
Date: Fri, 21 Jan 2011 18:31:53 -0500

On Jan 21, 2011, at 5:52 PM, Alasdair McAndrew wrote:

> This is a bit of a dumb question, I think, but in spite of using Matlab (and 
> Octave) for years, I actually have very little experience in low level file 
> handling.  Anyway, I have a file containing text and numerical data which I 
> can read into a cell array using textread.  But there doesn't seem to be a 
> comparable "textwrite" to write the amended cell array back to another text 
> file.
> 
> So - what is the most foolproof way of writing a cell array, containing text 
> and numerical data, to a text file?  
> 
> For example, suppose that every row in the array contains a first and last 
> name, along with age, height (in metres) and weight (in kilograms), like
> 
> Leaonhard, Euler, 74, 1.6, 72
> 
> So each row in the array contains five elements: two string values (the 
> names), one integer value, and two floating point values.
> 
> Thanks,
> Alasdair

Is the example below sufficient?

        octave:1> a = {"Leaonhard", "Euler", 74, 1.6, 72; "Ben", "Abbott", 48, 
1.83, 54};
        octave:2> fprintf ("%s, %s, %d, %.2f, %.1f\n", a'{:})
        Leaonhard, Euler, 74, 1.60, 72.0
        Ben, Abbott, 48, 1.83, 54.0

Ben



reply via email to

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