inserting row into an array

조회 수: 28 (최근 30일)
Rick
Rick 2014년 6월 14일
댓글: Ashwin Anil 2014년 6월 14일
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
Ashwin Anil
Ashwin Anil 2014년 6월 14일
First make A(2,:)=[0 0] Then b=a

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2014년 6월 14일
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,:)]

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by