MATLAB Function Reference |
for
, while
, switch
, try
, if
的結尾或表示最後一個索引。(indicate last index)
Syntax
Description
end
用來做 for
, while
, switch
, try
, if
的結束。若沒有 end
指令, for
, while
, switch
, try
, if
會等待更進一步的輸入(wait for further input)。每一個 end
和離本身最近且未被配成對的 for
, while
, switch
, try
, if
配在一起,以用來劃定其範圍。
end
也可以用來表示最後一個索引。當使用到第k個索引時, end = (size(x,k))
。這種用法的範例為 X(3:end)
和 X(1,1:2:end-1)
。若使用 end
增加陣列,例如 X(end+1)=5
,可以先確保 X
索引的存在。
You can overload the end
statement for a user object by defining an end
method for the object. The end
method should have the calling sequence end(obj,k,n)
, where obj
is the user object, k
is the index in the expression where the end
syntax is used, and n
is the total number of indices in the expression. For example, consider the expression
A(end-1,:)
MATLAB will call the end
method defined for A
using the syntax
end(A,1,2)
Examples
for i = 1:n if a(i) == 0 a(i) = a(i) + 2; end end
A = magic(5) A = 17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9 B = A(end,2:end) B = 18 25 2 9
See Also
break
, for
, if
, return
, switch
, try
, while
elseif | eomday |