extract sub matrix of sub matrix directly

4 Ansichten (letzte 30 Tage)
Abhijit Das
Abhijit Das am 20 Mär. 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

Akzeptierte Antwort

Wayne King
Wayne King am 20 Mär. 2012
Yes,
C = a(1:4,1:4,1);

Weitere Antworten (1)

Dr. Seis
Dr. Seis am 20 Mär. 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

Kategorien

Mehr zu Matrix Indexing 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