필터 지우기
필터 지우기

how to stop overwriting a matrix in a for loop in matlab

조회 수: 2 (최근 30일)
Reinhardt RADING
Reinhardt RADING 2021년 2월 9일
댓글: Reinhardt RADING 2021년 2월 9일
Hello all,
i'm stuck with this code.
I am trying to get the value of M.
M is the product of three matrices, iterated and multiplied 100 times. please see below.
for n =1:100
y = OUT.lin.matin(:,:,n); %gets valiue from a stored array
%y is a unitary matrix
x = OUT.lin.db0(n); %gets valiue from a stored array
% x is a scalar
w =[exp(1i*x),exp(1i*-x)]; % creating the exponential
k = diag(w); % creating a diagonal matrix of W
M = y*k*y';
end
I think M overrides each iteration, but i would like to get the results from the 100 iterations. Kindly assist.
Thanks in advance.

채택된 답변

KSSV
KSSV 2021년 2월 9일
M = zeros([],[],100) ; % give exact row and column size
for n =1:100
y = OUT.lin.matin(:,:,n); %gets valiue from a stored array
%y is a unitary matrix
x = OUT.lin.db0(n); %gets valiue from a stored array
% x is a scalar
w =[exp(1i*x),exp(1i*-x)]; % creating the exponential
k = diag(w); % creating a diagonal matrix of W
M(:,:,n) = y*k*y';
end
  댓글 수: 4
KSSV
KSSV 2021년 2월 9일
If the RHS is of size 2X2 use:
M = zeros(2,2,100) ; % give exact row and column size
Reinhardt RADING
Reinhardt RADING 2021년 2월 9일
Thanks this worked.
One more question! (Sorry,i'm still a novice in Matlab)
does the value of result of M(:,:,100) gives the multiplication for all values.
i.e
M1*M2*M3...M100
since
M1=y1*w1*y1'
M2 =y2*w2*y2'
.
.
M100=y100*w100*y100
Or do have to create another loop to get the product of every term?
Thanks again.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by