MATLAB中,在一个三维矩阵中如何提取出一个二维矩阵?

2024-12-02 06:34:24
推荐回答(2个)
回答1:

设原三维数组为a,用permute(a(:,1,:),[1 3 2])

>> a=rand(2,3,4)
a(:,:,1) =
    0.3046    0.1934    0.3028
    0.1897    0.6822    0.5417

a(:,:,2) =
    0.1509    0.3784    0.8537
    0.6979    0.8600    0.5936

a(:,:,3) =
    0.4966    0.8216    0.8180
    0.8998    0.6449    0.6602

a(:,:,4) =
    0.3420    0.3412    0.7271
    0.2897    0.5341    0.3093
>> b=permute(a(:,1,:),[1 3 2])
b =
    0.3046    0.1509    0.4966    0.3420
    0.1897    0.6979    0.8998    0.2897

回答2:

设原三维数组为a,用permute(a(:,1,:),[1 3 2]):

>> a=rand(2,3,4)
a(:,:,1) =
0.3046 0.1934 0.3028
0.1897 0.6822 0.5417

a(:,:,2) =
0.1509 0.3784 0.8537
0.6979 0.8600 0.5936

a(:,:,3) =
0.4966 0.8216 0.8180
0.8998 0.6449 0.6602

a(:,:,4) =
0.3420 0.3412 0.7271
0.2897 0.5341 0.3093
>> b=permute(a(:,1,:),[1 3 2])
b =
0.3046 0.1509 0.4966 0.3420
0.1897 0.6979 0.8998 0.2897