Effacer les filtres
Effacer les filtres

How to extract matrix element from an indexed matrix

1 vue (au cours des 30 derniers jours)
Suma
Suma le 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

Réponses (1)

Star Strider
Star Strider le 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.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by