inserting row into an array

71 Ansichten (letzte 30 Tage)
Rick
Rick am 14 Jun. 2014
Kommentiert: Ashwin Anil am 14 Jun. 2014
Hello,
I am trying to figure out what command I can use to add a row into an array by referencing that array.
An example, I want to have a reference array A = [1 1; 1 1; 1 1]
and I want to add [0, 0] into A such that
B = [1 1; 0 0; 1 1; 1 1]
by doing some sort of command that relates B to A but adds in that [0 0] into any row I want to add it to.
Such as B = A(2,[0 0]) but this is where I am stuck
Thank you
  1 Kommentar
Ashwin Anil
Ashwin Anil am 14 Jun. 2014
First make A(2,:)=[0 0] Then b=a

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Image Analyst
Image Analyst am 14 Jun. 2014
Try this:
A = [1 1; 1 1; 1 1] % Initial array.
rowToInsert = 2;
rowVectorToInsert = [0, 0];
B = [A(1:rowToInsert-1,:); rowVectorToInsert; A(rowToInsert:end,:)]

Weitere Antworten (0)

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by