Azzera filtri
Azzera filtri

How to extract matrix element from an indexed matrix

1 visualizzazione (ultimi 30 giorni)
Suma
Suma il 20 Mag 2014
Risposto: Star Strider il 20 Mag 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

Risposte (1)

Star Strider
Star Strider il 20 Mag 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.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by