フィルターのクリア

split a rectangular matrix

2 ビュー (過去 30 日間)
Elysi Cochin
Elysi Cochin 2019 年 4 月 1 日
コメント済み: Akira Agata 2019 年 4 月 1 日
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 日
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 件)

カテゴリ

Help Center および File ExchangeOperating on Diagonal Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by