Filter löschen
Filter löschen

How to extract matrix element from an indexed matrix

1 Ansicht (letzte 30 Tage)
Suma
Suma am 20 Mai 2014
Beantwortet: Star Strider am 20 Mai 2014
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

Antworten (1)

Star Strider
Star Strider am 20 Mai 2014
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.

Kategorien

Mehr zu Loops and Conditional Statements 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