1. Colon

x=1:4

% x=[1 2 3 4]

x=1:2:5

% x=[1 3 5]  (递增值为2)

2. Array

用一个矩阵作为例子:

A=[1 2 3; 4 5 6; 7 8 9]

A=

1 2 3

4 5 6

7 8 9

这个矩阵可看作一个二维数组。

可使用A(index)的形式寻址数组中的第index个元素,index从1开始。注意寻址顺序先列后行。于是:

% A(1)=1

% A(2)=4

% A(3)=7

% A(4)=2

也可以使用二维索引。然而索引值按先行后列方式给出:

% A(2,3)=6    (row 2,column 3)

可以使用Colon作为索引表达式,此时它表示对应索引位置的全部元素。

% A(:,1)   (A的第一列)

% A(2,:)   (A的第二行)

% A(:)      (A的全部元素(按列摆放为vector))

% A(:,:)    (A是vector或matrix的情况下,等同于A)

% A(1:3)   (等价于[A(1),A(2),A(3)])

Array and Colon in Matlab的更多相关文章

  1. Convert character array to string in MATLAB

    Matlab提取特征值是经常要读取多个图片文件,把文件名保存在数组中后再读取会出错.从stackoverflow中找到如下解决方法: I've a M by N matrix, each cell c ...

  2. Matlab与C/C++联合编程之Matlab以MEX方式调用C/C++代码(三)

    最近写了个Matlab程序,好慢呐……所以开始学习Matlab与C/C++混合编程.下面写了个测试代码,显示一个Double类型矩阵中的元素. 源代码 #include "mex.h&quo ...

  3. matlab numpy equivalents

    THIS IS AN EVOLVING WIKI DOCUMENT. If you find an error, or can fill in an empty box, please fix it! ...

  4. Multidimensional Arrays

    Overview An array having more than two dimensions is called a multidimensional array in the MATLAB® ...

  5. 【搬运】NumPy_for_Matlab_Users

    搬运自:http://scipy.github.io/old-wiki/pages/NumPy_for_Matlab_Users.html. 1.Introduction MATLAB和NumPy/S ...

  6. Matlab一个错误引发的血案:??? Error using ==> str2num Requires string or character array input.

    Matlab总遇到一些神奇的问题,让人摸不着头脑.昨天编写程序的时候遇到一个让我十分火大的问题,也是自己的matlab基础不好吧. 先描述一下问题,再GUI界面有个listbox,Tag属性是’lis ...

  7. 「Python」Numpy equivalent of MATLAB's cell array

    转自Stackoverflow.备忘用. Question I want to create a MATLAB-like cell array in Numpy. How can I accompli ...

  8. matlab中cell array的理解

    1. matlab中有一个函数iscell() 用于判断一个数组是不是cell array 参考:MATLAB Function Reference iscell Determine whether ...

  9. MATLAB知识-解决因缺少libsvm 而运行出现Y must be a vector or a character array.

    matlab版本R2014b 最近运行一个使用svmtrain的程序,出现以下错误: 这是因为是在设定路径里面没有libsvm.辛亏有一位师姐的电脑里面有libsvm的包,我直接用了,这样就不需要下载 ...

随机推荐

  1. C++ 中时钟函数的使用

    头文件: #incllude <time.h> 定义: clock_t var1, var2; 获取时间: var1 = clock(); 每过千分之一秒(1毫秒),调用clock()函数 ...

  2. Sping boot 之 @Value("${xxx}") 注解获取配置文件内容

    1.注解方式读取 1-1.@PropertySource配置文件路径设置,在类上添加注解,如果在默认路径下可以不添加该注解. 需要用@PropertySource的有: 例如非application. ...

  3. 解决Myeclipse ctrl+h带来的困扰

    解决Myeclipse ctrl+h带来的困扰 myeclipse的ctrl+h搜索功能给我们来查找文件定位类的方便,但同时也给我们带来两个困扰:一是搜出来的结果往往带着svn文件,一大推svn隐藏的 ...

  4. PHP5和PHP7的安装、PHP和apache的整合!

    1.PHP5的安装: 下载: wget -c http://cn2.php.net/distributions/php-5.6.36.tar.gz  (php5) wget -c http://cn2 ...

  5. Guarding the Chessboard(UVa 11214)

    本题题意: 输入一个n*m的棋盘,某些格子有标记,用最少的皇后占据或者攻击所以带标记的格子.皇后的攻击范围为同行同列和同对角线. 可以使用IDA*算法,即从样例可以发现只需要最多5个棋子就可以对棋盘上 ...

  6. mvc core2.1 Identity.EntityFramework Core 注册 (二)

    Startup.cs-> Configure app.UseAuthentication(); //启动验证 Controllers->AccountController.cs 新建 us ...

  7. hdu4300 Clairewd’s message 扩展KMP

    Clairewd is a member of FBI. After several years concealing in BUPT, she intercepted some important ...

  8. Go Example--锁

    package main import ( "fmt" "math/rand" "runtime" "sync" &qu ...

  9. crash - JNI WARNING: input is not valid modified utf-8: illegal continuation byte

    the key point is "Modified UTF-8" is not like "Regular UTF-8", a legal Rgular UT ...

  10. vue 2.0 vue.set的使用方法

    这里我定义了一个列表数据,我将通过三个不同的按钮来控制列表数据. 首先在列表中动态新增一条数据: <!DOCTYPE html><html><head lang=&quo ...