Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.



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 arraya 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!



