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

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

%
% Locate the last four nonzeros.

k = find(X,4,'last')

% Copyright 2015 The MathWorks, Inc.