Hello,
I have a 3x3 matrix and I want to make it 4x4 matrix by inserting a row and column of zero elements. How can I do that?
Thanks,
Rakesh

 채택된 답변

Star Strider
Star Strider 2019년 11월 16일

2 개 추천

One approach:
M = rand(3);
Mz = zeros(size(M,1)+1, size(M,2)+1);
Mz(1:size(M,1), 1:size(M,2)) = M;
producing (here):
Mz =
0.95717 0.14189 0.79221 0
0.48538 0.42176 0.95949 0
0.80028 0.91574 0.65574 0
0 0 0 0
Experiment to get the result you want.

댓글 수: 3

Rakesh Belchandan
Rakesh Belchandan 2019년 11월 16일
Thanks for the answer though. But what I want to do is:
3x3 matrix should become 4x4 matrix
but new 4x4 matrix has zero rows and columns at the 3rd row and 3rd column. 4th row and column will be last row and column of 3x3 matrix with zeros in place.
Rakesh Belchandan
Rakesh Belchandan 2019년 11월 16일
Oh great.. I can just chnage rows and columns in your solution. Thanks.
My pleasure.
That was not part of your original Question!
Just exchange the various rows and columns:
Mz([1 2 4 3],[1 2 4 3]) = Mz
producing for the original ‘Mz’:
Mz =
0.34039 0.75127 0.69908 0
0.58527 0.2551 0.8909 0
0.22381 0.50596 0.95929 0
0 0 0 0
and the ‘shuffled’ ‘Mz’:
Mz =
0.34039 0.75127 0 0.69908
0.58527 0.2551 0 0.8909
0 0 0 0
0.22381 0.50596 0 0.95929
Experiment to get the result you want.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

제품

릴리스

R2018b

질문:

2019년 11월 16일

댓글:

2019년 11월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by