Filter löschen
Filter löschen

diagonal matrix with ones

141 Ansichten (letzte 30 Tage)
Cristian
Cristian am 8 Mär. 2013
Hello I am trying to do a diagonal inferior matrix with a diagonal of ones but my diagonal have differentes valors. How do i do a matrix with diagonal of ones? Here is my code:
if true
% code
a=[6,9,7;6,2,0;1,8,3]
a=tril(a)
end
  1 Kommentar
Daniel Shub
Daniel Shub am 8 Mär. 2013
What would be really helpful is if in addition to your example input you could tell us what you want the output to be.

Melden Sie sich an, um zu kommentieren.

Antworten (7)

Sean de Wolski
Sean de Wolski am 8 Mär. 2013
Bearbeitet: Sean de Wolski am 8 Mär. 2013
eye(5)
?
more per clarification:
a = tril(magic(3));
a(logical(eye(size(a,1)))) = 1

Cristian
Cristian am 8 Mär. 2013
Hello Thanks for the answers but the firs answer just create a matriz of 5x5 with diagonal of ones and I need my matrix "a" but with diagonal of ones. The second answer has an error say: ??? Undefined function or variable 'n'.
Error in ==> Untitled2 at 3 [ii,jj]=ind2sub(size(a),1:n*m)
What should I do?
Thanks
  1 Kommentar
Sean de Wolski
Sean de Wolski am 8 Mär. 2013
see more in my answer above.

Melden Sie sich an, um zu kommentieren.


Leah
Leah am 8 Mär. 2013
a(eye(3))=1;
like that?
  3 Kommentare
Leah
Leah am 8 Mär. 2013
thanks Sean, I'm waiting on my license at my new job :)
Sean de Wolski
Sean de Wolski am 8 Mär. 2013
I'm sure your friendly sales rep would be happy to set you up with a trial :) !

Melden Sie sich an, um zu kommentieren.


Cristian
Cristian am 8 Mär. 2013
Well thaks Azzi Abdelmalek but now with your code matlab give me a triangular matrix with ones down of the diagonal and I need my diagonal just of ones. I could divide the last coefficent each row, and so have my diagonal with ones but I dont know manipulate rows and how I do that. Example I want that my triangular matrix: A=[6,9,7;6,2,0;1,8,3] A=tril(A)
A=[6,0,0;6,2,0;1,8,3]---->A=[1,0,0;3,1,0;1/3,8/3,1] This I want to do, having any matrix.
  2 Kommentare
Sean de Wolski
Sean de Wolski am 8 Mär. 2013
See my more section. Where'd the 1/3 and the 8/3 come from?
Cristian
Cristian am 8 Mär. 2013
Bearbeitet: Cristian am 8 Mär. 2013
That comes of divide by 3 all the third row to have my last coefficent with 1

Melden Sie sich an, um zu kommentieren.


Matt J
Matt J am 8 Mär. 2013
Bearbeitet: Matt J am 8 Mär. 2013
n=size(a,1);
a(1:n+1:end)=1;

Miroslav Balda
Miroslav Balda am 9 Mär. 2013
Your last comment explained how to construct the resulting matrix. You see, how important it is to precisely formulate your question.
Anew = diag(1./diag(A))'*tril(A)

Miroslav Balda
Miroslav Balda am 9 Mär. 2013
There is even simpler solutionof your problem:
Anew = diag(diag(A))\tril(A)

Kategorien

Mehr zu Operating on Diagonal Matrices 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!

Translated by