Thread Subject: shifting indices

Subject: shifting indices

From: Juliette Salexa

Date: 13 Jul, 2009 19:06:04

Message: 1 of 6

c(:,1:3)=repmat('abc',3,1)
c =
abc
abc
abc

now if I want to make
c=
'abc
'abc
'abc

I of course need to first shift all entries one column to the right.

I tried using this file: http://www.mathworks.com/matlabcentral/fileexchange/53

but when i use it, shift the characters to the right causes me to lose the last entry.


Is there a way around this ??

Subject: shifting indices

From: Matt

Date: 13 Jul, 2009 20:57:03

Message: 2 of 6

"Juliette Salexa" <juliette.physicist@gmail.com> wrote in message <h3g0ir$r0v$1@fred.mathworks.com>...
> c(:,1:3)=repmat('abc',3,1)
> c =
> abc
> abc
> abc
>
> now if I want to make
> c=
> 'abc
> 'abc
> 'abc
>
> I of course need to first shift all entries one column to the right.

why? Couldn't you just do the following

 c(:,1:3)=repmat('''abc',3,1)

Subject: shifting indices

From: Alan B

Date: 13 Jul, 2009 21:10:20

Message: 3 of 6

"Matt " <xys@whatever.com> wrote in message <h3g72v$krs$1@fred.mathworks.com>...
> "Juliette Salexa" <juliette.physicist@gmail.com> wrote in message <h3g0ir$r0v$1@fred.mathworks.com>...
> > c(:,1:3)=repmat('abc',3,1)
> > c =
> > abc
> > abc
> > abc
> >
> > now if I want to make
> > c=
> > 'abc
> > 'abc
> > 'abc
> >
> > I of course need to first shift all entries one column to the right.
>
> why? Couldn't you just do the following
>
> c(:,1:3)=repmat('''abc',3,1)

If you're starting with
c=
abc
abc
abc

and you need to get to
c=
'abc
'abc
'abc

then you just use horizontal concatenation, along with repmat.
c = repmat('abc',3,1); % what you have
c = [repmat('''',3,1) c]; % what you want

I really can't help but feel like there might be a better way of doing whatever you're trying to do, though. Are you passing the result of this to an eval() command or something similar?

Subject: shifting indices

From: dpb

Date: 13 Jul, 2009 21:22:04

Message: 4 of 6

Juliette Salexa wrote:
> c(:,1:3)=repmat('abc',3,1)
> c =
> abc
> abc
> abc
>
> now if I want to make
> c=
> 'abc
> 'abc
> 'abc
>
> I of course need to first shift all entries one column to the right.
...

Why not just

c(:,1:4)=repmat('''abc',3,1)

to begin with????

But I'm w/ Alan, there's bound to be more to the story; what are you
_REALLY_ after???

--

Subject: shifting indices

From: Jan Simon

Date: 13 Jul, 2009 21:33:04

Message: 5 of 6

Dear Juliette Salexa!

> c(:,1:3)=repmat('abc',3,1)
> c =
> abc
> abc
> abc
>
> now if I want to make
> c=
> 'abc
> 'abc
> 'abc

Another solution:
  c = repmat('abc',3,1)
  d = strcat(char(39), c)
I write "char(39)", because it looks less confusing than '''' in my browser, but both have the same binary representation.

Kind regards, Jan

Subject: shifting indices

From: Juliette Salexa

Date: 13 Jul, 2009 22:07:02

Message: 6 of 6

thanks everyone!

Alan's response:
c = [repmat('''',3,1) c];

did the trick.

I feel really dumb now ... I used to use that trick so often with numbers and in this context I didn't even think of it! Yea putting the apostrophes there from the beginning would screw other things up in my code (if you're curious, the abc wasn't defined by me but was generated by another code in a different function i just wrote it that way for simplicity in posing the quesiton).

Thanks Jan Simon, the char(39) trick is nice!

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