reshape把指定的矩阵改变形状,但是元素个数不变,

例如,行向量:

a = [1 2 3 4 5 6]

执行下面语句把它变成3行2列:

b = reshape(a,3,2)

执行结果:

b =

1 4

2 5

3 6

若a=[1 2 3

4 5 6

7 8 9]

可以从b中看到reshape是按列来读取的,如

a=[1  2 ; 3  4]

如果使用b=reshape(a,1,4)

则得到的结果是

b=[1 3 2 4]

如果想得到

b=[1 2 3 4]

需要使用

b=reshape(a',1,4)

因为reshape使用的列优先!

b转化回去是同样的道理。

 

使用reshpe后想得到b=[1 2 3 4 5 6 7 8 9]

只需要将a转置一下就可以了:

b=reshape(a',1,9)

----------------------------------------------

matlab中的解释如下:

RESHAPE Change size.

    RESHAPE(X,M,N) returns the M-by-N matrix whose elements

    are taken columnwise from X. An error results if X does

    not have M*N elements.

 

    RESHAPE(X,M,N,P,...) returns an N-D array with the same

    elements as X but reshaped to have the size M-by-N-by-P-by-...

    M*N*P*... must be the same as PROD(SIZE(X)).

 

    RESHAPE(X,[M N P ...]) is the same thing.

 

    RESHAPE(X,...,[],...) calculates the length of the dimension

    represented by [], such that the product of the dimensions

    equals PROD(SIZE(X)). PROD(SIZE(X)) must be evenly divisible

    by the product of the known dimensions. You can use only one

    occurrence of [].

 

    In general, RESHAPE(X,SIZ) returns an N-D array with the same

    elements as X but reshaped to the size SIZ. PROD(SIZ) must be

    the same as PROD(SIZE(X)).

 

源文档 <http://blog.sina.com.cn/s/blog_5feb3cea0100lz8b.html>

Matlab中reshape函数的使用的更多相关文章

  1. matlab中patch函数的用法

    http://blog.sina.com.cn/s/blog_707b64550100z1nz.html matlab中patch函数的用法——emily (2011-11-18 17:20:33) ...

  2. matlab中subplot函数的功能

    转载自http://wenku.baidu.com/link?url=UkbSbQd3cxpT7sFrDw7_BO8zJDCUvPKrmsrbITk-7n7fP8g0Vhvq3QTC0DrwwrXfa ...

  3. 【原创】Matlab中plot函数全功能解析

    [原创]Matlab中plot函数全功能解析 该帖由Matlab技术论(http://www.matlabsky.com)坛原创,更多精彩内容参见http://www.matlabsky.com 功能 ...

  4. matlab 中max函数用法

    Matlab中max函数在矩阵中求函数大小的实例如下:(1)C = max(A)返回一个数组各不同维中的最大元素.如果A是一个向量,max(A)返回A中的最大元素.如果A是一个矩阵,max(A)将A的 ...

  5. Matlab中plot函数全功能解析

    Matlab中plot函数全功能解析 功能 二维曲线绘图 语法 plot(Y)plot(X1,Y1,...)plot(X1,Y1,LineSpec,...)plot(...,'PropertyName ...

  6. matlab中cumsum函数

    matlab中cumsum函数通常用于计算一个数组各行的累加值.在matlab的命令窗口中输入doc cumsum或者help cumsum即可获得该函数的帮助信息. 格式一:B = cumsum(A ...

  7. 『转载』Matlab中fmincon函数获取乘子

    Matlab中fmincon函数获取乘子 一.输出结构 [x,fval,exitflag,output,lambda] = fmincon(......) 二.结构说明 lambda结构 说     ...

  8. matlab中norm函数的用法

    格式:n=norm(A,p) 功能:norm函数可计算几种不同类型的矩阵范数,根据p的不同可得到不同的范数 以下是Matlab中help norm 的解释 NORM   Matrix or vecto ...

  9. matlab中fprintf函数的具体使用方法

    matlab中fprintf函数的具体使用方法实例如下: fprintf函数可以将数据按指定格式写入到文本文件中.其调用格式为: 数据的格式化输出:fprintf(fid, format, varia ...

随机推荐

  1. javascript中的 类初始化,遍历for in 以及with的用法

    <script type="text/javascript"> function member(name,gender){ this.name=name; this.g ...

  2. Effective Java 29 Consider typesafe heterogeneous containers

    When a class literal is passed among methods to communicate both compile-time and runtime type infor ...

  3. Greenplum源码编译安装(单机及集群模式)完全攻略

    公司有个项目需要安装greenplum数据库,让我这个gp小白很是受伤,在网上各种搜,结果找到的都是TMD坑货帖子,但是经过4日苦战,总算是把greenplum的安装弄了个明白,单机及集群模式都部署成 ...

  4. ubuntu16.04服务器配置ssh免密登录

    原版资料英文,链接在此  https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2 在客户端操作 ssh-k ...

  5. 对于大学4年的反思(续),记我的ThoughtWorks面试

    之前我写了一篇对于大学四年的反思,时隔一个月,为什么我这么快就要来写这篇续章呢?主要有两个原因,第一是感谢静子姐姐,记得知乎上有个回答里面说过人生需要有贵人的帮助,遇到贵人是一件很幸运的事情.我想,静 ...

  6. C#委托与C语言函数指针及函数指针数组

    C#委托与C语言函数指针及函数指针数组 在使用C#时总会为委托而感到疑惑,但现在总新温习了一遍C语言后,才真正理解的委托. 其实委托就类似于C/C++里的函数指针,在函数传参时传递的是函数指针,在调用 ...

  7. UVALive 6092 Catching Shade in Flatland --枚举+几何计算

    题意:x=[-200,200],y=[-200,200]的平面,一天中太阳从不同角度射到长椅(原点(0,0))上,有一些树(用圆表示),问哪个时刻(分钟为单位)太阳光线与这些圆所交的弦长总和最长.太阳 ...

  8. UESTC 288 青蛙的约会 扩展GCD

    设两只青蛙跳了t步,则此时A的坐标:x+mt,B的坐标:y+nt.要使的他们在同一点,则要满足: x+mt - (y+nt) = kL (p是整数) 化成: (n-m)t + kL = x-y (L ...

  9. POJ 1703 Find them,Catch them ----种类并查集(经典)

    http://blog.csdn.net/freezhanacmore/article/details/8774033?reload  这篇讲解非常好,我也是受这篇文章的启发才做出来的. 代码: #i ...

  10. Linux命令学习-top

    top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器.下面详细介绍它的使用方法. top - 01:06:48 up  1:22,   ...