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

Version 1.0.0.0 (638 Bytes) by H. Brian Hui
FINDN is the FIND function for n-D matrix
716 Downloads
Updated 19 Mar 2009

No License

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 (2024). 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 .

MATLAB Release Compatibility
Created with R2008a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Linear Algebra in Help Center and MATLAB Answers
Tags Add Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0.0