Ami*_*kra 0 arrays matlab matrix
如何在Matlab中编写一个函数,该函数采用每列中具有单个1值的矩阵并返回此1的索引.
例如:如果输入为x = [0 0 1; 1 0 0; 0 1 0],则返回索引= [2 3 1]
find 确实是要走的路
[indices,~] = find(x);
Run Code Online (Sandbox Code Playgroud)
如果你想更加隐秘地做,或者find出于某种原因讨厌,你也可以使用cumsum:
indices = 4 - sum(cumsum(x,1),1);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
45 次 |
| 最近记录: |