X = magic(6);%生成一个魔方阵
X(1:2:end) = 0;%从第一个数开始,以2为步进,一直到最后
>> X = magic(3)
X =
8 1 6
3 5 7
4 9 2
>> X(1:2:end) = 0
X =
0 1 0
3 0 7
0 9 0
%%%%%%%%%%%注意,从上往下,从左往右依次增大,对应的序号为:
X =
1 4 7
2 5 8
3 6 9
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X =
8 1 6
3 5 7
4 9 2
>> X(5)
ans =
5
>> X(8)
ans =
7
%%%%%%%%%%%%%%%%%%也可以使用坐标表示
X =
8 1 6
3 5 7
4 9 2
>> X(1,2)
ans =
1
%%%%%%%%%%%%%%%%% find函数
>> X = magic(3)
X =
8 1 6
3 5 7
4 9 2
>> I = find(X,3,'last')//从后往前,在X中找到3个 不为0 的数,返回数值所在的位置
I =
7
8
9
>> X = magic(3)
X =
8 1 6
3 5 7
4 9 2
>> X(1:2:end) = 0
X =
0 1 0
3 0 7
0 9 0
>> I = find(X,3,'last')
I =
4
6
8