[Top][All Lists]

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

Re: Write a cell array to a textfile

From: Alasdair McAndrew
Subject: Re: Write a cell array to a textfile
Date: Sat, 22 Jan 2011 15:34:19 +1100

Thanks very much.  And if I append a file identification variable to fprintf I can write the results to a file.


On Sat, Jan 22, 2011 at 10:31 AM, Ben Abbott <address@hidden> wrote:

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



reply via email to

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