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:
Merge/Combining strings

Subject: Merge/Combining strings

From: kamuran turksoy

Date: 10 Jul, 2011 20:24:12

Message: 1 of 10

Hi,

To merge two strings i use strcat:

A=strcat('a','b');

and when i check the size of A or 'ab' it shows 1,2. But I want ab as one string (one variable) and the size 1,1. Is there anyway to do it?

Thank you

Subject: Merge/Combining strings

From: dpb

Date: 10 Jul, 2011 20:37:29

Message: 2 of 10

On 7/10/2011 3:24 PM, kamuran turksoy wrote:
> Hi,
>
> To merge two strings i use strcat:
>
> A=strcat('a','b');
>
> and when i check the size of A or 'ab' it shows 1,2. But I want ab as
> one string (one variable) and the size 1,1. Is there anyway to do it?
...

doc cellstr

--

Subject: Merge/Combining strings

From: kamuran turksoy

Date: 10 Jul, 2011 20:56:09

Message: 3 of 10

dpb <none@non.net> wrote in message <ivd2i6$33f$1@speranza.aioe.org>...
> On 7/10/2011 3:24 PM, kamuran turksoy wrote:
> > Hi,
> >
> > To merge two strings i use strcat:
> >
> > A=strcat('a','b');
> >
> > and when i check the size of A or 'ab' it shows 1,2. But I want ab as
> > one string (one variable) and the size 1,1. Is there anyway to do it?
> ...
>
> doc cellstr
>
> --
 cellstr does not work for my case, because i also will make some convolution using nonnumeric convolution :

http://www.mathworks.com/matlabcentral/newsreader/view_thread/73114

neither conv function nor function for nunnumeric convolution does not support cell operation.

Subject: Merge/Combining strings

From: ImageAnalyst

Date: 10 Jul, 2011 22:58:09

Message: 4 of 10

kamuran turksoy
I guess I don't understand. I ran this:
A=strcat('a','b')
sizeA = size(A)
lengthA = length(A)

and got this:
A =
ab
sizeA =
     1 2
lengthA =
     2

Just what I'd expect. Size returns how many rows and columns. You
have an array with "a" in the first element (column) and "b" in the
second element (column), both in the same row. So size() correctly
reports that you have a character array with 1 row and two columns.
length() works on vectors and says, correctly, that the length of the
row vector is 2. I'm puzzled as to why you want that character array
reported as 1,1 (one row, one column) -- unless as dpb suggested you
want to stuff the two element character array into a single element (a
single "cell") of a cell array.
ImageAnalyst

Subject: Merge/Combining strings

From: kamuran turksoy

Date: 10 Jul, 2011 23:04:09

Message: 5 of 10

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <d6da5494-c9eb-4591-b788-6c4e2b70b933@b21g2000yqc.googlegroups.com>...
> kamuran turksoy
> I guess I don't understand. I ran this:
> A=strcat('a','b')
> sizeA = size(A)
> lengthA = length(A)
>
> and got this:
> A =
> ab
> sizeA =
> 1 2
> lengthA =
> 2
>
> Just what I'd expect. Size returns how many rows and columns. You
> have an array with "a" in the first element (column) and "b" in the
> second element (column), both in the same row. So size() correctly
> reports that you have a character array with 1 row and two columns.
> length() works on vectors and says, correctly, that the length of the
> row vector is 2. I'm puzzled as to why you want that character array
> reported as 1,1 (one row, one column) -- unless as dpb suggested you
> want to stuff the two element character array into a single element (a
> single "cell") of a cell array.
> ImageAnalyst

I know that matlab gives size and length correctly, the thing that i want to do merge a and b as one symbol. As i wrote before with cell case i can not do convolution calculations thats why i need do it as symbolic

Subject: Merge/Combining strings

From: ImageAnalyst

Date: 11 Jul, 2011 01:06:05

Message: 6 of 10

On Jul 10, 7:04 pm, "kamuran turksoy" <kamuranturk...@gmail.com>
wrote:
> I know that matlab gives size and length correctly, the thing that i want to do merge a and b as one symbol. As i wrote before with cell case i can not do convolution calculations thats why i need do it as symbolic
---------------------------------------------------------------------
You've lost me again. How can you do convolution with letters? I've
only heard of it being done with numbers.

Subject: Merge/Combining strings

From: kamuran turksoy

Date: 11 Jul, 2011 01:25:12

Message: 7 of 10

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <9d6df781-7bb0-40c7-8dd7-492bc063dafe@eb1g2000vbb.googlegroups.com>...
> On Jul 10, 7:04 pm, "kamuran turksoy" <kamuranturk...@gmail.com>
> wrote:
> > I know that matlab gives size and length correctly, the thing that i want to do merge a and b as one symbol. As i wrote before with cell case i can not do convolution calculations thats why i need do it as symbolic
> ---------------------------------------------------------------------
> You've lost me again. How can you do convolution with letters? I've
> only heard of it being done with numbers.

ok, let me expalin you a little more. Firstly with that function i can make convolution between number and symbols (letter)
 function w = conv(u,v)
   % CONV Nonnumeric convolution.
   % W = CONV(U,V) is the convolution of symbolic vectors U and V.
   % length(w) = length(u)+length(v)-1
   % w(k) = sum(u(j)*v(k+1-j)), j = max(1,k+1-length(v):min(k,length(u))
   
   % Form Toeplitz matrix from v.
   m = length(u);
   n = length(v);
   p = m+n-1;
   T = [v(:); zeros(m,1)]*ones(1,m);
   T = reshape(T(1:m*p),p,m);
   
   % Convolve
   w = T*u(:);
   
   % Return row vector if appropriate
   if size(u,2) > size(u,1)
      w = w.';
   end

Then, this should work:

    >> syms a b c d
    >> u = [a b c d];
    >> v = [3 1 4 1 5 9];
    >> conv(u,v).'
     
    ans =
     
               3*a
             a+3*b
         4*a+b+3*c
       a+4*b+c+3*d
       5*a+b+4*c+d
     9*a+5*b+c+4*d
         9*b+5*c+d
           9*c+5*d
               9*d

And the reason for symbolic convolution that i want to do, solving diophantine equation.

A*F+B*G=C here A, B C are known and F and G are unknown and all of them are polynomials.

A=a0+a1*z+a2*z^2+...+an*z^n-1;
F=f0+f1*z+f2*z^2+...+fn*z^na-1;
G=g0+g1*z+g2*z^2+...+gn*z^nb-1;
B=b0+b1*z+b2*z^2+...+bm*z^m-1;

As you see in F and G polynomials i have lots of unknown coefficients, to find these coefficient we have to use convolution.

C=conv(A,F)+conv(B,G)

I hope these information is enough for you to understand

Subject: Merge/Combining strings

From: Steven_Lord

Date: 11 Jul, 2011 01:31:12

Message: 8 of 10



"kamuran turksoy" <kamuranturksoy@gmail.com> wrote in message
news:ivdjdo$ie$1@newscl01ah.mathworks.com...
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message
> <9d6df781-7bb0-40c7-8dd7-492bc063dafe@eb1g2000vbb.googlegroups.com>...
>> On Jul 10, 7:04 pm, "kamuran turksoy" <kamuranturk...@gmail.com>

*snip*

> And the reason for symbolic convolution that i want to do, solving
> diophantine equation.
>
> A*F+B*G=C here A, B C are known and F and G are unknown and all of them
> are polynomials.
>
> A=a0+a1*z+a2*z^2+...+an*z^n-1;
> F=f0+f1*z+f2*z^2+...+fn*z^na-1;
> G=g0+g1*z+g2*z^2+...+gn*z^nb-1;
> B=b0+b1*z+b2*z^2+...+bm*z^m-1;
>
> As you see in F and G polynomials i have lots of unknown coefficients, to
> find these coefficient we have to use convolution.
>
> C=conv(A,F)+conv(B,G)

Just define the coefficients symbolically, multiply the polynomials, and use
COEFFS with SOLVE. No string manipulation or convolution required.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Merge/Combining strings

From: kamuran turksoy

Date: 11 Jul, 2011 02:29:09

Message: 9 of 10

Dear Steve

I tried the way you told me. But still there are some problems.
 For my F polynomial i have f0 f1 and f2 coefficient for G i have g0 g1 and g2.

coefficient of T-(A*F+B*G) gave me
[ 1 - f0, 1 - f1 - f0/2, - f0/2 - f1/2 - f2, - (3*f0)/5 - f1/2 - f2/2 - g0, - (3*f1)/5 - f2/2 - g1, - (3*f2)/5 - g2]

when i try to solve these coefficient, for first one it should find f0 and for second one it should put the value of f0 instead of f0 but here it puts f0 as it self:

coeff of F=[ 1, 1 - f0/2, - f0/2 - f1/2];
coeff of G=[ - (3*f0)/5 - f1/2 - f2/2, - (3*f1)/5 - f2/2, -(3*f2)/5]

Could you please help me how to put values of coefficient in each loop. i am finding coefficient in for loop.

Subject: Merge/Combining strings

From: Steven_Lord

Date: 11 Jul, 2011 13:29:47

Message: 10 of 10



"kamuran turksoy" <kamuranturksoy@gmail.com> wrote in message
news:ivdn5l$9a2$1@newscl01ah.mathworks.com...
> Dear Steve
> I tried the way you told me. But still there are some problems.
> For my F polynomial i have f0 f1 and f2 coefficient for G i have g0 g1 and
> g2.
>
> coefficient of T-(A*F+B*G) gave me
> [ 1 - f0, 1 - f1 - f0/2, - f0/2 - f1/2 - f2, - (3*f0)/5 - f1/2 - f2/2 -
> g0, - (3*f1)/5 - f2/2 - g1, - (3*f2)/5 - g2]
>
> when i try to solve these coefficient, for first one it should find f0 and
> for second one it should put the value of f0 instead of f0 but here it
> puts f0 as it self:
>
> coeff of F=[ 1, 1 - f0/2, - f0/2 - f1/2];
> coeff of G=[ - (3*f0)/5 - f1/2 - f2/2, - (3*f1)/5 - f2/2, -(3*f2)/5]
>
> Could you please help me how to put values of coefficient in each loop. i
> am finding coefficient in for loop.

syms f0 f1 f2
F = [ 1, 1 -f0/2, -f0/2 -f1/2];
G = [ -(3*f0)/5-f1/2-f2/2, -(3*f1)/5-f2/2, -(3*f2)/5];

Use the COEFFS function to extract the coefficients of T-(A*F+B*G) and SOLVE
for all the coefficients being equal to 0 simultaneously.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

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