![]() |
如何在MATLAB中调整矩阵的大小?
假设我有一个[B]1×12[/B]矩阵,我想将其大小调整为[B]4×3[/B]矩阵。我该怎么办?
我当前的解决方案有点丑陋: for n = 1:(length(mat)/3) out(n,1:3) = mat( ((n-1)*3 + 1):((n-1)*3 + 3) ); end 有一个更好的方法吗? 回答: reshape当然是正确的解决方案,如[URL="https://stackoverflow.com/a/793581/5211833"]@gnovice所述[/URL] 。 reshape一个不错的功能是它允许: A = 1:12; B = reshape(A,4,[]); B = 1 5 9 2 6 10 3 7 11 4 8 12 因此,如果您不知道会有多少列,那么reshape会为您计算出来。同样,如果您不进行修改,则reshape将填充行数。 C = reshape(A,[],4) C = 1 4 7 10 2 5 8 11 3 6 9 12 [url=https://stackoverflow.com/questions/793574]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 23:32。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.