extract sub matrix of sub matrix directly

4 views (last 30 days)
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

Accepted Answer

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

More Answers (1)

Dr. Seis
Dr. Seis on 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

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!