matlab reshape函数

语法

(1)B = reshape(A,m,n)

用法:
B=reshape(A,m,n) 返回m*n矩阵B,它的元素是获得A的行宽度。如果A没有m*n元素,得到一个错误结果。

例子:

<span style="font-size:18px;">>> A=rand(1,10)</span>
结果:

<span style="font-size:18px;">A =

  Columns 1 through 8

    0.1622    0.7943    0.3112    0.5285    0.1656    0.6020    0.2630    0.6541

  Columns 9 through 10

    0.6892    0.7482
</span>

<span style="font-size:18px;">>> B=reshape(A,5,2)</span>
结果:
B =

    0.1622    0.6020
    0.7943    0.2630
    0.3112    0.6541
    0.5285    0.6892
    0.1656    0.7482

(2)

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

B = reshape(A,[m n p ...])
返回一个和A有相同元素的n维数组,但结构变为m * n * p * …

例如:

<span style="font-size:18px;">>> A=rand(1,12)</span>
结果:A矩阵
A =

  Columns 1 through 8

    0.4505    0.0838    0.2290    0.9133    0.1524    0.8258    0.5383    0.9961

  Columns 9 through 12

    0.0782    0.4427    0.1067    0.9619

>> D=reshape(A,2,3,2)

D(:,:,1) =

    0.4505    0.2290    0.1524
    0.0838    0.9133    0.8258


D(:,:,2) =

    0.5383    0.0782    0.1067
    0.9961    0.4427    0.9619

(3)

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

>> C=reshape(A,5,[])
结果:

C =

    0.1622    0.6020
    0.7943    0.2630
    0.3112    0.6541
    0.5285    0.6892
    0.1656    0.7482

(4)

B = reshape(A,siz)

返回一个与A相同元素的n维阵列,但是改造依据siz,一个向量改造改造的阵列的维度。数值prod(siz)必须和prod(size(A))相同。
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值