Re: How to insert a row to a matrix rapidly



In article <1128823613.635149.180040@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>, "fl"
<rxjwg98@xxxxxxxxx> wrote:

> Hi,
> We know that it is to eliminate a row (or a column) by []. For example,
>
> a = [0:9].';
> b = reshape(a, 5, 2);
> b(2, :) = []
>
> b =
>
> 0 5
> 2 7
> 3 8
> 4 9
>
> Now, I want to insert one row of [1, 1] to the eliminated position.
> That is:
>
> b =
>
> 0 5
> 1 1
> 2 7
> 3 8
> 4 9
>
> Although I can copy the three rows first, then I insert one row [1, 1]
> and copy back the last three rows, I don't like that way. How to do
> this more efficiently?
>
> Thank you.
--------------------
Hello,

This is as efficient a method as I know for inserting [1 1] at the
second row of b:

b = [b(1,:);[1 1];b(2:end,:)]

(Remove "xyzzy" and ".invalid" to send me email.)
Roger Stafford
.



Relevant Pages

  • Re: Matrix update
    ... > Does anyone know how to do this using matrix operations in Matlab? ... Roger Stafford ... Prev by Date: ...
    (comp.soft-sys.matlab)
  • RE: Cut&Paste Macro
    ... > I need a Cut and Paste macro which will cut every second row (A2,A4, ... > etc) and Paste them to a destination one by one. ... > TIA ... Prev by Date: ...
    (microsoft.public.excel.worksheet.functions)
  • Re: simplify a symbolic exression
    ... My Symbolic Math Toolbox does the same thing as yours on that, ... thing stage fright! ... Roger Stafford ... Prev by Date: ...
    (comp.soft-sys.matlab)
  • Re: Creation of a matrix from indexed variables
    ... like entering directly rows or columns... ... > Stephane. ... Roger Stafford ... Prev by Date: ...
    (comp.soft-sys.matlab)
  • THANKS, GUYS!!! MUCH BETTER.
    ... Volkan wrote: ... Roger's code assumes that the second row of A is sorted. ... Roger Stafford wrote: ... to assume that when you said "sorted array", ...
    (comp.soft-sys.matlab)