📅  最后修改于: 2021-01-07 02:21:44             🧑  作者: Mango
MATLAB中的end关键字主要用于两个目的:
end
a = ones(4)
for k = 1:length(a)
if a(k) == 1
a(k) = 0;
end
end
disp('......')
disp(a)
disp('...end')
输出:
a = 4×4
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
......
0 1 1 1
0 1 1 1
0 1 1 1
0 1 1 1
...end
示例:使用end关键字指示最后一个数组索引:
a = randi(100,4,4)
b = a(end,2:end) % here first end argument indicates the last row,
%and the second indicates the columns number from 2 to the last
a = 4×4
43 66 68 66
92 4 76 18
80 85 75 71
96 94 40 4
b = 1×3
94 40 4