help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: reshaping vector


From: James Sherman Jr.
Subject: Re: reshaping vector
Date: Mon, 24 May 2010 14:36:17 -0400

On Mon, May 24, 2010 at 2:20 PM, Ron.Simonson <address@hidden> wrote:
James Sherman Jr. wrote:
> You're not looking to reshape the vector, but to replicate the vector.
> This can be done using the "repmat" function.  You can type "help
> repmat" to see the details, but to do just what you have there, it can
> be done like:
>
> A = 1:4;
> AA = repmat(A, [1 4]);
>
> 2010/5/24 Miĥail Vasiljev <address@hidden <mailto:address@hidden>>
>
>     Hello!
>
>     Probably this question is answered somewhere but searching google was
>     not helpful. I have a vector, say,
>
>     A = 1:4;
>
>     I want to create another vector, with a form
>
>     AA = 1,2,3,4,1,2,3,4,1,2,3,4;
>
>     i.e. I need a vector who's elements are elements of vector A, just
>     repeated n times. How can I achieve this?
>
>     Thank you!
>
>     --
>     Miĥail Vasiljev <address@hidden <mailto:address@hidden>>
>
>     _______________________________________________
>     Help-octave mailing list
>     address@hidden <mailto:address@hidden>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

My first inclination was to "solve" this problem with
a = [1:4];
aa = [a a a a];
works for the task at hand but not easily expanded to a large
size.  The much better solution provided by James Sherman

A = 1:4;
AA = repmat(A, [1 4]);

is much better when you may want to expand this to very large
sizes.  But

A = 1:4;
AA = repmat(A,1,4);

also works, much like James Sherman's solution.  Is there any
particular reason for your use of square brackets?  Is it primarily
a coding style issue?  I use octave for a lot of my data analysis
needs but I am by no means much more than a novice user.  I learn
a lot about the language by reading the excellent posts by the
very generous help from the folks that provide so many helpful
solutions on this list.  Thank you all.  Thank you also to Professor
Eaton for keeping this great tool going.

Talk to you later.  Ron.
_______________________________________________
Help-octave mailing list
address@hidden
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

For why I use the vector notation and 2 argument form of repmat, as opposed to the 3 argument form, its mostly just notation and in this case it surely is just notation.  I just probably default to using the vector notation because if you ever need to use repmat with more than 2 dimensions, you need to use the vector notation.  But for just 2 dimensions, it is just a style choice.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]