www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/LastSeveralNonzeroElementsExample.m

    %% Last Several Nonzero Elements
% Create a 6-by-6 magic square matrix with all of the odd-indexed elements
% equal to zero.

% Copyright 2015 The MathWorks, Inc.

X = magic(6);
X(1:2:end) = 0

%%
% Locate the _last_ four nonzeros.
k = find(X,4,'last')