Thread Subject: Adding Text columns to a Matrix

Subject: Adding Text columns to a Matrix

From: Raju Gain

Date: 17 Sep, 2008 18:41:03

Message: 1 of 5

Hello,

I have created a variable A = zeros(5,5). The first three columns contain double values. I have another variable which contains strings for example 'Yes' or 'No'. I am trying to add this variable to A(:,4) (to make it as the fourth column) but I keep getting an error which says " The following error occurred converting from cell to double:
Error using ==> double
Conversion to double from cell is not possible."

I am not sure what I am doing wrong. It should be quite straight forward. Can someone help?

Thanks

Subject: Adding Text columns to a Matrix

From: Barry Williams

Date: 17 Sep, 2008 18:55:04

Message: 2 of 5

"Raju Gain" <supernova5271@yahoo.com> wrote in message <garivv$sni$1@fred.mathworks.com>...
> Hello,
>
> I have created a variable A = zeros(5,5). The first three columns contain double values. I have another variable which contains strings for example 'Yes' or 'No'. I am trying to add this variable to A(:,4) (to make it as the fourth column) but I keep getting an error which says " The following error occurred converting from cell to double:
> Error using ==> double
> Conversion to double from cell is not possible."
>
> I am not sure what I am doing wrong. It should be quite straight forward. Can someone help?
>
> Thanks

Search the documentation for information on creating a cell array. This will hold both numerical and text data.
Barry

Subject: Adding Text columns to a Matrix

From: someone

Date: 17 Sep, 2008 19:01:03

Message: 3 of 5

"Raju Gain" <supernova5271@yahoo.com> wrote in message <garivv$sni$1@fred.mathworks.com>...
> Hello,
>
> I have created a variable A = zeros(5,5). The first three columns contain double values. I have another variable which contains strings for example 'Yes' or 'No'. I am trying to add this variable to A(:,4) (to make it as the fourth column) but I keep getting an error which says " The following error occurred converting from cell to double:
> Error using ==> double
> Conversion to double from cell is not possible."
>
> I am not sure what I am doing wrong. It should be quite straight forward. Can someone help?
>
> Thanks

% This should get you started:

A = zeros(5,5)
B = num2cell(A)

B{4,1} = 'yes'
B{1,4} = 'no'

% etc.

Subject: Adding Text columns to a Matrix

From: Walter Roberson

Date: 17 Sep, 2008 19:05:06

Message: 4 of 5

"Raju Gain" <supernova5271@yahoo.com> wrote in message <garivv$sni$1@fred.mathworks.com>...

> I have created a variable A = zeros(5,5). The first three
> columns contain double values. I have another variable
> which contains strings for example 'Yes' or 'No'. I am
> trying to add this variable to A(:,4)

You cannot mix data classes in a single array. You cannot
have text in a numeric array.

The closest you can get is the approach the other poster
suggested, which is to use a cell array -- or you could
use a structure which had a field for the numerics and
another field for the text. But neither cell arrays
nor structures will display "nicely" as columns of numbers
intermixed with columns of text.

Subject: Adding Text columns to a Matrix

From: Raju Gain

Date: 17 Sep, 2008 23:34:02

Message: 5 of 5

Thanks everyone..
Got it working..


"Walter Roberson" <roberson@ibd.nrc-cnrc.gc.ca> wrote in message <garkd2$ifv$1@fred.mathworks.com>...
> "Raju Gain" <supernova5271@yahoo.com> wrote in message <garivv$sni$1@fred.mathworks.com>...
>
> > I have created a variable A = zeros(5,5). The first three
> > columns contain double values. I have another variable
> > which contains strings for example 'Yes' or 'No'. I am
> > trying to add this variable to A(:,4)
>
> You cannot mix data classes in a single array. You cannot
> have text in a numeric array.
>
> The closest you can get is the approach the other poster
> suggested, which is to use a cell array -- or you could
> use a structure which had a field for the numerics and
> another field for the text. But neither cell arrays
> nor structures will display "nicely" as columns of numbers
> intermixed with columns of text.

Tags for this Thread

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.

rssFeed for this Thread
 

MATLAB Central Terms of Use

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 Terms prior to use.

Contact us at files@mathworks.com