【问题标题】:How to find the the most value index of N index from matrix M MATLAB如何从矩阵 M MATLAB 中找到 N 索引的最大值索引
【发布时间】:2014-03-05 05:24:12
【问题描述】:

假设我有一个矩阵 M 500x500

我想找到在 M 中具有最大价值的前 100 个索引

我的想法是对数据 M 进行降序排序,然后使用 find 进行比较

[x,y] = find(M == sort(M(:),'descend'), 100, 'first');

但是当我运行程序时发现错误

我觉得大概M == sort(M(:),'descend')这部分

你能帮帮我吗?

【问题讨论】:

  • 尝试使用M(:,:) 而不是M(:),因为您的矩阵是二维的

标签: arrays matlab sorting indexing find


【解决方案1】:

您不需要find。只需使用sort 的第二个输出:

[~, iSorted] = sort(M(:),'descend');
[x y] = ind2sub(size(M), iSorted(1:100));

【讨论】:

    猜你喜欢
    • 2011-01-06
    • 1970-01-01
    • 1970-01-01
    • 2013-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多