reshape,permute函数matlabA = [1,2,3,4;5,6,7,8;9,10,11,12;13,14,15,16];如何得到B:B(:,:,1) = [1,2;5,6];B(:,:,2) = [3,4;7,8];B(:,:,3) = [9,10;13,14];B(:,:,4) = [11,12;15,16];
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/16 21:45:31
reshape,permute函数matlabA = [1,2,3,4;5,6,7,8;9,10,11,12;13,14,15,16];如何得到B:B(:,:,1) = [1,2;5,6];B(:,:,2) = [3,4;7,8];B(:,:,3) = [9,10;13,14];B(:,:,4) = [11,12;15,16];
reshape,permute函数matlab
A = [1,2,3,4;5,6,7,8;9,10,11,12;13,14,15,16];
如何得到B:
B(:,:,1) = [1,2;5,6];
B(:,:,2) = [3,4;7,8];
B(:,:,3) = [9,10;13,14];
B(:,:,4) = [11,12;15,16];
reshape,permute函数matlabA = [1,2,3,4;5,6,7,8;9,10,11,12;13,14,15,16];如何得到B:B(:,:,1) = [1,2;5,6];B(:,:,2) = [3,4;7,8];B(:,:,3) = [9,10;13,14];B(:,:,4) = [11,12;15,16];
这个转换可以通过reshape、permute函数实现:
>> B=reshape(permute(reshape(A,[2 2 4]),[1 3 2]),[2 2 4])
B(:,:,1) =
1 2
5 6
B(:,:,2) =
3 4
7 8
B(:,:,3) =
9 10
13 14
B(:,:,4) =
11 12
15 16
不过,个人认为,上述实现方式的表达式比较难懂,不如直接使用cat函数:
>> B=cat(3,A(1:2,1:2),A(1:2,3:4),A(3:4,1:2),A(3:4,3:4))
B(:,:,1) =
1 2
5 6
B(:,:,2) =
3 4
7 8
B(:,:,3) =
9 10
13 14
B(:,:,4) =
11 12
15 16