i have a matrix as
input = [1 0 0 0; 0 1 0 0; 0 0 1 0];
how can i split a the input matrix as
output1 = [1 0 0 0; 0 0 0 0; 0 0 0 0];
output2 = [0 0 0 0; 0 1 0 0; 0 0 0 0];
output3 = [0 0 0 0; 0 0 0 0; 0 1 0 0];
store output1-3 in a single matrix named output with n-dimension.
matrix input can be of any dimension but rectangular matrix and only diagonal values will be there.

 채택된 답변

Akira Agata
Akira Agata 2019년 4월 1일

1 개 추천

How about the following?
input = [1 0 0 0; 0 1 0 0; 0 0 1 0];
output = zeros([size(input),size(input,1)]);
for kk = 1:size(input,1)
output(kk,:,kk) = input(kk,:);
end

댓글 수: 2

madhan ravi
madhan ravi 2019년 4월 1일
Note: Naming a variable input is not a good idea, it will shadow the in-built function input().
Akira Agata
Akira Agata 2019년 4월 1일
Yes, that's true. Thank you for your additional comment !

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

질문:

2019년 4월 1일

댓글:

2019년 4월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by