Manipulate matrix of different dimension

1 回表示 (過去 30 日間)
kamal
kamal 2019 年 8 月 14 日
回答済み: Andrei Bobrov 2019 年 8 月 14 日
I have a matrix like this
q2.PNG
I want to create a square matrix of size 5. At first row of matrix 1 only element 1 is present. using that element i want matrix as m1 -m1 at 1st and second position of first row in matrix 2.
q1.PNG
Please help me the logic
  3 件のコメント
KSSV
KSSV 2019 年 8 月 14 日
(2,2) element is m1+m2+m5 or m1+m2?
kamal
kamal 2019 年 8 月 14 日
m2+m5

サインインしてコメントする。

採用された回答

Andrei Bobrov
Andrei Bobrov 2019 年 8 月 14 日
mm = [0 0 1;1 2 5;0 2 3 ;0 3 4; 0 4 5];
m = size(mm,1);
n = max(mm(:));
lo = eye(m,n) ~= 0;
M = zeros(m,n);
[ii,~,v]=find(mm);
M(sub2ind([m,n],ii,mm(mm~=0))) = -v;
M = M.*~lo;% or M(lo) = 0;
M = M + M.';
M(lo)=-sum(M,2);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

製品


リリース

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by