请输入您要查询的百科知识:

 

词条 reshape
释义

函数简介

函数功能:重新调整矩阵的行数、列数、维数。在matlab命令窗口中键入doc reshape或help reshape即可获得该函数的帮助信息。

调用格式:

B = reshape(A,m,n)

返回一个m*n的矩阵B, B中元素是按列从A中得到的。如果A中元素个数不等于m*n, 则会引发错误。

B = reshape(A,m,n,p,...)

返回一个和A具有相同元素的n维数组。但B的尺寸是m*n*p*...,m*n*p*...必须和prod(size(A))相等。即A和B元素个数相等。

B = reshape(A,[m n p ...])

B = reshape(A,...,[],...)

B = reshape(A,siz)

相关函数: shiftdim, squeeze, circshift, permute, repmat

程序示例

close all; clear; clc;

A = [1 2 3; 4 5 6; 7 8 9; 10 11 12] % 4 by 3

B = reshape(A, 2, 6) % 2 by 6

% C = reshape(A, 2, 4) % error

% D = reshape(A, 2, 10) % error

E = reshape(A, 2, 3, 2) % 2 by 3 by 2

运行结果:

A =

1 2 3

4 5 6

7 8 9

10 11 12

B =

1 7 2 8 3 9

4 10 5 11 6 12

E(:,:,1) =

1 7 2

4 10 5

E(:,:,2) =

8 3 9

11 6 12

随便看

 

百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。

 

Copyright © 2004-2023 Cnenc.net All Rights Reserved
更新时间:2025/2/3 8:53:47