FIND for n-D: Find indices and values of nonzero elements in n-D matrix

FINDN is the FIND function for n-D matrix

You are now following this Submission

Just like the FIND function in Matlab, FINDN is a simple function which will find the indices and values of nonzero elements in a n-D matrix

function [sub v] = findn(A)
% INPUT: A: n-D matrix
% OUTPUT: sub: the k x n index matrix (k is the number of the nonzeros)
v: a column or row vector v of the nonzero entries in A
USAGE:
[sub ] = findn(A)

TESTING CODE:

A = zeros(4,3,5,7);
A(4,2,1,4)=1;
A(2,3,4,6)=2;
A(1,2,3,4)=3;
findn(A)

AUTHOR:
Brian H. Hui (brianhui@alumni.usc.edu)
PhD candidate, Electrical Engineering, University of Southern California

Cite As

H. Brian Hui (2026). FIND for n-D: Find indices and values of nonzero elements in n-D matrix (https://www.mathworks.com/matlabcentral/fileexchange/23360-find-for-n-d-find-indices-and-values-of-nonzero-elements-in-n-d-matrix), MATLAB Central File Exchange. Retrieved .

Categories

Find more on Linear Algebra in Help Center and MATLAB Answers

General Information

MATLAB Release Compatibility

  • Compatible with any release

Platform Compatibility

  • Windows
  • macOS
  • Linux
Version Published Release Notes Action
1.0.0.0