Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Output cell array

Subject: Output cell array

From: Ze Kai Ng

Date: 8 Nov, 2012 11:10:08

Message: 1 of 4

I have been having troubles generating an output to a file. output.txt with a cell array that consists of strings and numbers.

e.g:outvec=[64927 3051114511.00000 5.11772042811932e-10 1953994975.00000 'string']

Please advice. Thanks.

Subject: Output cell array

From: Justin Ashmall

Date: 8 Nov, 2012 11:18:10

Message: 2 of 4

"Ze Kai Ng" wrote in message <k7g3ug$c1e$1@newscl01ah.mathworks.com>...
> I have been having troubles generating an output to a file. output.txt with a cell array that consists of strings and numbers.
> e.g:outvec=[64927 3051114511.00000 5.11772042811932e-10 1953994975.00000 'string']

Firstly, tell us what you have tried and what went wrong.

Secondly, the line of code you give is not a cell array, you need curly braces { }.

Justin

Subject: Output cell array

From: Ze Kai Ng

Date: 8 Nov, 2012 11:55:08

Message: 3 of 4

"Justin Ashmall" wrote in message <k7g4di$dha$1@newscl01ah.mathworks.com>...
> "Ze Kai Ng" wrote in message <k7g3ug$c1e$1@newscl01ah.mathworks.com>...
> > I have been having troubles generating an output to a file. output.txt with a cell array that consists of strings and numbers.
> > e.g:outvec=[64927 3051114511.00000 5.11772042811932e-10 1953994975.00000 'string']
>
> Firstly, tell us what you have tried and what went wrong.
>
> Secondly, the line of code you give is not a cell array, you need curly braces { }.
>
> Justin

Hi Justin, sorry I was using it as an example as I got a large cell 1x23 with large numbers.
outvec={64927 3051114511.00000 5.11772042811932e-10 1953994975.00000 'string'}

Tried using save function.
>> save 'output.txt' outvec -ascii

but I get this error.
Warning: Attempt to write an unsupported data type to an ASCII file.
Variable 'outvec' not written to file.

There is an output file but it is blank.

Subject: Output cell array

From: Justin Ashmall

Date: 8 Nov, 2012 12:22:08

Message: 4 of 4

> outvec={64927 3051114511.00000 5.11772042811932e-10 1953994975.00000 'string'}
>
> Tried using save function.
> >> save 'output.txt' outvec -ascii
>

It's not much help, but this is expected. From "doc save" for ascii files:
    * Each variable must be a two-dimensional double or character array.

i.e. cell arrays are not supported.

In general, saving a cell array that contains mixed numbers and strings is not particularly simple in MATLAB. Your best best is to store the numbers and strings in separate arrays, and then use save() or dlmwrite() for example.

If you want to use a mixed cells array, try reading this for an example:
http://www.mathworks.com/help/matlab/import_export/write-to-delimited-data-files.html#br2ypq2-1

Or take a look on the file exchange - I can see some functions there.

Justin

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us