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. iOS之 PJSIP静态库编译(一)

    首先放上pjsip官方网站http://www.pjsip.org/download.htm 下载的时候注意while the .bz2 has LF line-ends and is for Uni ...

  2. Effective Java 44 Write doc comments for all exposed API elements

    Principle You must precede every exported class, interface, constructor, method, and field declarati ...

  3. forfiles命令批量删除N天前文件

    在整理手上几台SQL SERVER 2000的数据库备份时,一方面为了方便快速还原数据库,另外一方面为了备份冗余.备份方式统一(先备份到本地,然后收上磁带),将以前通过Symantec Backup ...

  4. oracle-删除归档日志

    rman target user/password; DELETE ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE-7';

  5. EasyUI ComboGrid 分页

    一.使用场景 下拉框可以很方便地为我们提供选择功能,通过下拉框我们可以便捷地选择某个值,而不需要手动输入.在EasyUI中有ComboGrid与之对应.ComboGrid既可以当中下拉框来使用,又可以 ...

  6. MCS51系列单片机实用技术部分课件

  7. Zero

    Zero是我的极品现任BOSS曾用过的QQ昵称.那时候,我正跟京姑娘闹七年之痒,甩她而去赋闲在老家.Zero通过朋友介绍,看了我几篇零散的博客,就给我打电话,让我过来聊聊.本来我跟京姑娘也没有大矛盾, ...

  8. codeforces 709D D. Recover the String(构造)

    题目链接: D. Recover the String time limit per test 1 second memory limit per test 256 megabytes input s ...

  9. Codeforces Round #270 D Design Tutorial: Inverse the Problem --MST + DFS

    题意:给出一个距离矩阵,问是不是一颗正确的带权树. 解法:先按找距离矩阵建一颗最小生成树,因为给出的距离都是最短的点间距离,然后再对每个点跑dfs得出应该的dis[][],再对比dis和原来的mp是否 ...

  10. Codeforces 369E Valera and Queries --树状数组+离线操作

    题意:给一些线段,然后给m个查询,每次查询都给出一些点,问有多少条线段包含这个点集中的一个或多个点 解法:直接离线以点为基准和以线段为基准都不好处理,“正难则反”,我们试着求有多少线段是不包含某个查询 ...