Obtaining an updated diagonal Matrices

Good day everyone. Pls, can someone assist on generating a diagonal matrices from each row of a random matrix as: M=rand(N,2) where N=20 iterations =300 The matrices i want to generate, at first is, for iter=1:iterations for i=1:N generate a diagonal matrices of 2x2 from M i.e 20 diagonal matrices of size 2x2.
for the update matrices meaning the first ones are previous, so the update or current matrices should be for j=2:iterations-1 for i=1:N generate a 20 diagonal matrices of size 2x2 up to j, Let say something like P(i, ,j)=diag(, ,j) where P(i, ,j) are the current generated 20 diagonal matrices of 2x2 up to j. Thank you. Best regards,

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 3월 26일

0 개 추천

N=20;
itr = 300;
i1 =...
bsxfun(@plus,bsxfun(@plus,1:4:4*N,[0;3]),reshape(0:4*N:(itr-1)*4*N,1,1,[]));
out = zeros(2,2,N,itr);
M=rand(N*itr,2);
out(i1) = M.';

댓글 수: 1

Abul A
Abul A 2012년 3월 26일
I am much grateful Mr. andrei bobrov, big kudos. It really generated the matrices but i want to it, to be like if,
N=20;
iterations=300;
M=rand(N,2);
for iter=1:iterations
for i=1:N
G(i,:,1)=diag(M( ));
meaning it will generate a 20 diagonal matrices of 2x2 for the iter=1:300 and for i=1:N
then the next
for j=2:iter-1 or for j=2:299
for i=N
G(i,:,j)=diag(M(, ,j))
meaning for j=2:299 and for i=1:20 it will generate 20 diagonal matrices of 2x2 each iteration upto j . Instead of doing it one by one. Hope i put it clear. Once more thanks

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2012년 3월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by