Thread Subject: exporting cell and double

Subject: exporting cell and double

From: Jessica

Date: 12 Jun, 2008 02:52:01

Message: 1 of 6

Hi,

I have two columns of values:

A=
‘a’
‘b’
‘c’
.
.
.

And

B=
1
2
3
.
.
.

Such that ‘A’ is considered as cell and ‘B’ is considered
as double. Is it possible to create one file (that can be
exported to excel) that combines the two columns such that
the final result looks like the following (in which the two
variables are stored in separate columns):

‘a’ 1
‘b’ 2
‘c’ 3

(I haven’t been able to do this because the columns are of
different types).

Thanks!

Subject: exporting cell and double

From: Siddharth Shankar

Date: 12 Jun, 2008 03:35:03

Message: 2 of 6

You mean,... something like this:

>> M = {1 'a'; 2 'b'; 3 'c'}

M =

    [1] 'a'
    [2] 'b'
    [3] 'c'

>> whos
  Name Size Bytes Class Attributes

  M 3x2 390 cell


>> xlswrite('myfile.xls',M)

This works perfectly, you might want to try this and see if
this is what you are looking for.

"Jessica " <jyorzinski@ucdavis.edu> wrote in message
<g2q30h$ftr$1@fred.mathworks.com>...
> Hi,
>
> I have two columns of values:
>
> A=
> ‘a’
> ‘b’
> ‘c’
> .
> .
> .
>
> And
>
> B=
> 1
> 2
> 3
> .
> .
> .
>
> Such that ‘A’ is considered as cell and ‘B’ is considered
> as double. Is it possible to create one file (that can be
> exported to excel) that combines the two columns such
that
> the final result looks like the following (in which the
two
> variables are stored in separate columns):
>
> ‘a’ 1
> ‘b’ 2
> ‘c’ 3
>
> (I haven’t been able to do this because the columns are
of
> different types).
>
> Thanks!
>

Subject: exporting cell and double

From: Jessica

Date: 12 Jun, 2008 17:00:20

Message: 3 of 6

"Siddharth Shankar" <siddharth.shankar@gmail.com> wrote in
message <g2q5h7$b0e$1@fred.mathworks.com>...
> You mean,... something like this:
>
> >> M = {1 'a'; 2 'b'; 3 'c'}
>
> M =
>
> [1] 'a'
> [2] 'b'
> [3] 'c'
>
> >> whos
> Name Size Bytes Class Attributes
>
> M 3x2 390 cell
>
>
> >> xlswrite('myfile.xls',M)
>
> This works perfectly, you might want to try this and see
if
> this is what you are looking for.
>
> "Jessica " <jyorzinski@ucdavis.edu> wrote in message
> <g2q30h$ftr$1@fred.mathworks.com>...
> > Hi,
> >
> > I have two columns of values:
> >
> > A=
> > ‘a’
> > ‘b’
> > ‘c’
> > .
> > .
> > .
> >
> > And
> >
> > B=
> > 1
> > 2
> > 3
> > .
> > .
> > .
> >
> > Such that ‘A’ is considered as cell and ‘B’ is
considered
> > as double. Is it possible to create one file (that can
be
> > exported to excel) that combines the two columns such
> that
> > the final result looks like the following (in which the
> two
> > variables are stored in separate columns):
> >
> > ‘a’ 1
> > ‘b’ 2
> > ‘c’ 3
> >
> > (I haven’t been able to do this because the columns are
> of
> > different types).
> >
> > Thanks!
> >
>

Thanks for this suggestion. This is close to what I need to
do except that 'A' and 'B' are stored variables (and
contain hundreds of values) and I don't want to have to
type them out manually in 'M.'

Subject: exporting cell and double

From: William

Date: 12 Jun, 2008 19:22:01

Message: 4 of 6

> Thanks for this suggestion. This is close to what I need
to
> do except that 'A' and 'B' are stored variables (and
> contain hundreds of values) and I don't want to have to
> type them out manually in 'M.'

If A is a cell array then you may have to convert it to a
character array for this to work right, but you should be
able to do a loop (if you can't figure out the
vectorization of it). This text is assuming you've
unpacked the cell and stored the array as a character
array.

for i=1:1:lenght(A)
NewArray={A(i),B(i)};
end

Subject: exporting cell and double

From: us

Date: 12 Jun, 2008 19:54:02

Message: 5 of 6

"Jessica ":
<SNIP creating output from mixed contents

one of the solutions

     a={
          'a'
          'bb'
          'ccc'
     };
     b=(1:3).';
     m=[a,num2cell(b)]
%{
     m =
     'a' [1]
     'bb' [2]
     'ccc' [3]
%}
% now, put it into an excel sheet, eg,
% xlswrite(fnam,m);
% there will be two cols with the contents of <a> and <b>

us

Subject: exporting cell and double

From: Jessica

Date: 12 Jun, 2008 23:56:02

Message: 6 of 6

"us " <us@neurol.unizh.ch> wrote in message
<g2rusq$dg6$1@fred.mathworks.com>...
> "Jessica ":
> <SNIP creating output from mixed contents
>
> one of the solutions
>
> a={
> 'a'
> 'bb'
> 'ccc'
> };
> b=(1:3).';
> m=[a,num2cell(b)]
> %{
> m =
> 'a' [1]
> 'bb' [2]
> 'ccc' [3]
> %}
> % now, put it into an excel sheet, eg,
> % xlswrite(fnam,m);
> % there will be two cols with the contents of <a> and <b>
>
> us


Thanks, that worked!

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
code us 12 Jun, 2008 15:55:08
cell us 12 Jun, 2008 15:55:08
xlswrite us 12 Jun, 2008 15:55:08
rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com