row of all 8’s

조회 수: 3 (최근 30일)
Chung Di
Chung Di 2017년 11월 23일
댓글: Kaushik Lakshminarasimhan 2017년 11월 24일
Suppose O=ones(n) Now how can I insert a row of all 8’s between rows (n-3) and (n-2) of matrix O and insert a column of all 8’s between columns 1 and 2 of matrix )

채택된 답변

Kaushik Lakshminarasimhan
Kaushik Lakshminarasimhan 2017년 11월 23일
편집: Kaushik Lakshminarasimhan 2017년 11월 24일
N = 10;
X = ones(N); % create a matrix of 1s
X = [X(1:N-3,:) ; 8*ones(1,N) ; X(N-2:end,:)]; % add a row of 8s between (N-3)th and (N-2)th row
X = [X(:,1) 8*ones(N+1,1) X(:,2:end)]; % add a column of 8s between 1st and 2nd columns
  댓글 수: 9
Chung Di
Chung Di 2017년 11월 24일
It will be really helpful if you use comments beside the code, so that I can understand the code, rather than copy paste Thank you so much
Kaushik Lakshminarasimhan
Kaushik Lakshminarasimhan 2017년 11월 24일
I didn't add comments because I thought it was self-explanatory. Anyway, I have edited my answer to include comments.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by