I want only upper triangular matrix
Manipulate matrix of different dimension
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
kamal
am 14 Aug. 2019
Beantwortet: Andrei Bobrov
am 14 Aug. 2019
I have a matrix like this
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.
Please help me the logic
3 Kommentare
Akzeptierte Antwort
Andrei Bobrov
am 14 Aug. 2019
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Operators and Elementary Operations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!