matlab 数组操作作业

写出下列语句的计算结果及作用

1.A= [2 5 7 3

    1 3 4 2];    创建二维数组并赋值

2.[rows, cols] = size(A);    ​把A的尺寸赋值给数组,rows为行,cols为列

3.odds = 1:2:cols;    ​创建从1到cols的数组,步数为二

4.disp('odd columns of A using predefined indices')    ​显示一句话

5.A(:,odds)    ​创建一个数组,它由A中的第odds列组成

6.disp('odd columns of A using anonymous indices')    ​显示一句话

7.A(end,1:2:end)    ​创建子矩阵,由A的end行,奇数元素组成

8.disp('put evens into odd values in a new array')    显示一句话​

9.B(:,odds) = A(:,2:2:end)    ​把A的偶数列放在新矩阵B的奇数列上,没有赋值的列都置0

10.disp('set the even values in B to 99')    ​显示一句话

11.B(1,2:2:end) = 99    ​把B中第一行偶数列的元素置为99

12.disp('find the small values in A')    ​显示一句话

13.small = A < 4    ​数组逻辑运算,创建一个尺寸与A相同的矩阵,A中小于4的元素位置置1,其它位置置0

14.disp('add 10 to the small values')    ​显示一句话

15.A(small) = A(small) + 10     ​small为1的位置对应的A中的元素加10

16.disp('this can be done in one ugly operation')    ​输出一句话

17.A(A<4) = A(A<4)+10    ​A中小于4的值加10(无变化,因为没有小于4的值)

18.small_index = find(small)    ​返回逻辑数组small对应的A中元素的线性化位置,暴露了matlab数组的线性化本质

19.A(small_index)= A(small_index)+100    ​small_index对应的A中的元素加100;

原文地址:https://www.cnblogs.com/sq800/p/13153020.html