Vectorized FIND with 'FIRST' option

版本 1.1.0.0 (5.1 KB) 作者: Bruno Luong
Find the first non-zero element(s) along row/column - or any other dimension
3.0K 次下载
更新时间 2010/5/19

查看许可证

Up to now, to find the first non-zero element of a matrix along a column (for example) user might:

1. Use for-loop with FIND command
for j=1:size(A,2)
... = find(A(:,j), 1, 'first');
end

2. Use other vectorized methods, often time not very straight-forwards (MAX, LOGICAL, SPARSE, etc...). This method creates temporary arrays and scan such the arrays few times while doing some calculation.

3. Write the basic FOR-LOOP algorithm to accomplish the task.

The FINDFIRST command does just the same, but implemented using MEX engine which should be faster than any of the above. It can handle 'FIRST', 'LAST' option, and return more than one FIND count.

NOTE: not yet tested on Linux (gcc)

引用格式

Bruno Luong (2025). Vectorized FIND with 'FIRST' option (https://www.mathworks.com/matlabcentral/fileexchange/24641-vectorized-find-with-first-option), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R2009a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Sparse Matrices 的更多信息
标签 添加标签
致谢

启发作品: csearch

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.1.0.0

Fix a bug when 'last' in invoked on 64-bit platform

1.0.0.0