triind2sub

版本 1.0.0.0 (1.6 KB) 作者: James Ashton
Convert the indices of pdist results to subscripts of its input
50.0 次下载
更新时间 2017/6/1

查看许可证

triind2sub is a helper function for working with the output of pdist. It's analogous to the way ind2sub works with linear indices of arrays to find the corresponding subscripts. Using triind2sub avoids the time and space required by using the squareform function.
Example:

square = [0 0; 0 1; 1 1; 1 0];
% find the distances between the corners of the unit square
dists = pdist(square);
% report the pairs of points with maximum separation
[col, row] = triind2sub(size(square), find(dists == max(dists)))
% report the pairs of points with minimum separation
[col, row] = triind2sub(size(square), find(dists == min(dists)))

Without triind2sub you could instead use

[col, row] = find(squareform(dists) == max(dists))
[col, row] = find(squareform(dists) == min(dists))

to achieve similar results but this approach is more than ten times slower, produces duplicates and requires more memory.

引用格式

James Ashton (2024). triind2sub (https://www.mathworks.com/matlabcentral/fileexchange/63205-triind2sub), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2016a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Statistics and Machine Learning Toolbox 的更多信息

Community Treasure Hunt

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

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