Thread Subject: concatinating strings--error

Subject: concatinating strings--error

From: Leyo Joseph

Date: 3 Feb, 2012 19:47:21

Message: 1 of 6

Hello,

Please help me figure this out:

vb=[-13,67,-227,598,-1353,2839,-6242,24537,16172,-5275,2469,-1171,508,-187,52,-9;];
 
  coe=dec2hex(bin2dec(dec2bin(mod((vb),2^16),16)));
%coe is the two's complement of each elements of vb. It is 16*4 char
for k=1:15
    coef(k)=[coe(k,1),coe(k,2),coe(k,3),coe(k,4)];
end
% Coef is an 16*1 array.

This is giving the error==>??? Subscripted assignment dimension mismatch.

Thanks

Subject: concatinating strings--error

From: Mark Proulx

Date: 3 Feb, 2012 20:34:26

Message: 2 of 6

Is this a homework assignment?

Subject: concatinating strings--error

From: dpb

Date: 3 Feb, 2012 21:06:11

Message: 3 of 6

On 2/3/2012 1:47 PM, Leyo Joseph wrote:
...
> %coe is the two's complement of each elements of vb. It is 16*4 char
> for k=1:15
> coef(k)=[coe(k,1),coe(k,2),coe(k,3),coe(k,4)];
> end
> % Coef is an 16*1 array.
>
> This is giving the error==>??? Subscripted assignment dimension mismatch.

Yes, written that way you're selecting four separate characters and
trying to assign them to one array location. That would need it to be
written as

coef(k,:)=[coe(k,1),coe(k,2),coe(k,3),coe(k,4)];

It would be simpler to write

coef(k,:)=coe(k,:);

but that is the same in the end as

coef=coe;

--

Subject: concatinating strings--error

From: Leyo Joseph

Date: 3 Feb, 2012 23:15:32

Message: 4 of 6

dpb <none@non.net> wrote in message <jghi82$pt3$1@speranza.aioe.org>...
> On 2/3/2012 1:47 PM, Leyo Joseph wrote:
> ...
> > %coe is the two's complement of each elements of vb. It is 16*4 char
> > for k=1:15
> > coef(k)=[coe(k,1),coe(k,2),coe(k,3),coe(k,4)];
> > end
> > % Coef is an 16*1 array.
> >
> > This is giving the error==>??? Subscripted assignment dimension mismatch.
>
> Yes, written that way you're selecting four separate characters and
> trying to assign them to one array location. That would need it to be
> written as
>
> coef(k,:)=[coe(k,1),coe(k,2),coe(k,3),coe(k,4)];
>
> It would be simpler to write
>
> coef(k,:)=coe(k,:);
>
> but that is the same in the end as
>
> coef=coe;
>
> --Hello,
Thanks for the answer, but this is not what I am looking for.
for example when vb=-13, coe(1,1)=F,coe(1,2)=Fcoe(1,3)=F and coe(1,4)=3
when vb =67 coe(2,:0)=0043.
I want coef(1,1)=FFF3 (Thatis coef(1,1)=coe(1,:) and
coef(2,1)=coe(2,:).... so on and
coef(16,1)=coe(16,:)

Subject: concatinating strings--error

From: dpb

Date: 3 Feb, 2012 23:28:10

Message: 5 of 6

On 2/3/2012 5:15 PM, Leyo Joseph wrote:
...

> Thanks for the answer, but this is not what I am looking for.
> for example when vb=-13, coe(1,1)=F,coe(1,2)=Fcoe(1,3)=F and coe(1,4)=3
> when vb =67 coe(2,:0)=0043. I want coef(1,1)=FFF3 (Thatis
> coef(1,1)=coe(1,:) and
> coef(2,1)=coe(2,:).... so on and coef(16,1)=coe(16,:)

As a string?

If so, you need cellstr()--

 >> coef=cellstr(coe);
 >> coef{1}
ans =
FFF3
 >> whos coef
   Name Size Bytes Class

   coef 16x1 1600 cell array

Grand total is 80 elements using 1600 bytes

 >>

NB the need to dereference the cell contents w/ the curly braces instead
of parens above

--

Subject: concatinating strings--error

From: Leyo Joseph

Date: 3 Feb, 2012 23:37:10

Message: 6 of 6

dpb <none@non.net> wrote in message <jghqic$dp2$1@speranza.aioe.org>...
> On 2/3/2012 5:15 PM, Leyo Joseph wrote:
> ...
>
> > Thanks for the answer, but this is not what I am looking for.
> > for example when vb=-13, coe(1,1)=F,coe(1,2)=Fcoe(1,3)=F and coe(1,4)=3
> > when vb =67 coe(2,:0)=0043. I want coef(1,1)=FFF3 (Thatis
> > coef(1,1)=coe(1,:) and
> > coef(2,1)=coe(2,:).... so on and coef(16,1)=coe(16,:)
>
> As a string?
>
> If so, you need cellstr()--
>
> >> coef=cellstr(coe);
> >> coef{1}
> ans =
> FFF3
> >> whos coef
> Name Size Bytes Class
>
> coef 16x1 1600 cell array
>
> Grand total is 80 elements using 1600 bytes
>
> >>
>
> NB the need to dereference the cell contents w/ the curly braces instead
> of parens above
>
> --Thanks...this is waht I am lloking for.
Thanks for your help.

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

Contact us at files@mathworks.com