필터 지우기
필터 지우기

How to extract matrix element from an indexed matrix

조회 수: 1 (최근 30일)
Suma
Suma 2014년 5월 20일
답변: Star Strider 2014년 5월 20일
Hi,
How can I extract matrix element from an indexed matrixS(:,:,k)? I know S(2,2) would extract 2nd row,2nd column but how to do it with S(:,:,k) which are calculated in loop k=1:n?
Thanks

답변 (1개)

Star Strider
Star Strider 2014년 5월 20일
You can extract them as (MxN) matrices, but you have to do operations on them inside the loop (unless you want to do the extremely unwise and strongly discouraged operation of creating individually-named (MxN) matrices).
The squeeze function is your friend here.
For example, this works:
S = randi(25, 7, 6, 5);
v = randi(10, 6, 1);
for k1 = 1:size(S,3)
R(:,:) = squeeze(S(:,:,k1));
Q(:,k1) = R*v;
end
The Q matrix here contains the results of the vector multiplications inside the loop.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by