ELE*_*ANT 3 matlab matrix reshape
如何在MATLAB中重塑矩阵,最好使用reshape?
一个简单的矩阵设置:
A = [1 4 7 10; 2 5 8 11; 3 6 9 12]
Run Code Online (Sandbox Code Playgroud)
我想重塑一下
B = [1 4; 2 5; 3 6; 7 10; 8 11; 9 12]
Run Code Online (Sandbox Code Playgroud)
我尝试了很多设置reshape,但我无法弄清楚.
1 2 3 4
5 6 7 8
Run Code Online (Sandbox Code Playgroud)
重塑成
1 2
5 6
3 4
7 8
Run Code Online (Sandbox Code Playgroud)
你可以使用reshape和置换:
reshape(permute(reshape(A,size(A,1),2,[]),[1 3 2]),[],2)
Run Code Online (Sandbox Code Playgroud)
感谢@LuisMendo建议修改答案,以避免取决于大小A.