extract sub matrix of sub matrix directly

3 vues (au cours des 30 derniers jours)
Abhijit Das
Abhijit Das le 20 Mar 2012
I have matrix a m-by-n-by-p.
b=a(:,:,1) is a sub matrix of a.
I want to extract sub matrix of b (say c) so that
c=b(1:4, 1:4)
Can I extract c from matrix a such as
c=[a(:,:,1)](1:4, 1:4) This means
c=b(1:4, 1:4)
With regards -Abhijit

Réponse acceptée

Wayne King
Wayne King le 20 Mar 2012
Yes,
C = a(1:4,1:4,1);

Plus de réponses (1)

Dr. Seis
Dr. Seis le 20 Mar 2012
You will have to use reshape if you take a sub-set a different way, e.g.:
>> a = rand(3,3,3);
>> b = a(1:2,1:2,1)
b =
0.3922 0.7060
0.6555 0.0318
>> b = a(1:2,1,1:2)
b(:,:,1) =
0.3922
0.6555
b(:,:,2) =
0.6948
0.3171
>> b = reshape(a(1:2,1,1:2),[2,2])
b =
0.3922 0.6948
0.6555 0.3171

Catégories

En savoir plus sur Matrix Indexing 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