Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Topic: Combine string matrix and integer matrix
Replies: 7   Last Post: Aug 25, 2013 9:11 AM

 Messages: [ Previous | Next ]
 John Dickson Posts: 19 Registered: 10/30/11
Re: Combine string matrix and integer matrix
Posted: Aug 23, 2013 11:45 PM

dpb <none@non.net> wrote in message <kv8s2n\$a81\$1@speranza.aioe.org>...
> On 8/23/2013 2:13 PM, Sincloe Brans wrote:
> > Hi Saravanan
> > It works if I specify the items inside my B matrix as you described
> > ('a', 'b',...), however it is not in a matrix format though.
> > my B matrix keeps changing so I can only specify it as [B] or {B} while
> > concatenation. My output C = [A B] where A is integer matrix and B is
> > string matrix, dimensions are assumed to be same.

>
> You _can't_ concatenate different types into the same array.
>
> You _can_ make C a cell array w/ a numeric and a character array in the
> cells.
>
> Or, you can convert all the numeric values to strings and create a
> larger character array--a cell array would probably be more handy.
>
> What is the end result of this desired operation, pray tell? If you
> were describe what your actual objective is in the end instead of how to
> do what is essentially impossible a better solution may ensue.
>
> --
>

Let A =
1 3 4 4
3 3 4 5
4 4 5 5
5 4 4 5

B = a b c
a a a
a c a
a b c

My end result should be e.g.
C= [A B] =
1 3 4 4 a b c
3 3 4 5 a a a
4 4 5 5 a c a
5 4 4 5 a b c

Converting all to any one type is totally fine.
I used 'cellstr' to convert the B matrix and then I combined using cell array,
C = [num2cell(A) cellstr (B)]

when I do this way i see the strings with ' ' in each cell which is hard if I want to save in excel and do some calculations.
My final matrix should have no 'a', just a (as shown in C matrix).
Not sure if it is possible in matlab, if not I can live with this.

Thank you so much for your time and helping!

Date Subject Author
8/23/13 John Dickson
8/23/13 Saravanan Mani
8/23/13 John Dickson
8/23/13 dpb
8/23/13 John Dickson
8/24/13 dpb
8/25/13 John Dickson
8/25/13 dpb