【问题标题】:how to repalce the bigger index of upper triangular matrix by lower index.and according to that want to change matrix label number. MATLAB如何用下索引替换上三角矩阵的较大索引。并据此更改矩阵标签号。 MATLAB
【发布时间】:2014-03-06 17:37:45
【问题描述】:

我有一个检测到的说话人变化点的向量`

SCP=[10 25 43];

从这里我做了一个矩阵

seg_result=
          start-time   end-time
speaker1  1            10
speaker2  10           25
speaker3  25           43
speaker4  43           end-time of audio wav(for ex: 50)

在这之后我做了齐次说话人聚类。结果是下三角矩阵总是为零的矩阵,矩阵如下,

cluster_result=

0   -567   345   324
0     0    567   768
0     0     0    534
0     0     0     0

然后我检测到矩阵中的负数。

for i=2:length(cluster_result)
    for j=(i+1):length(cluster_result)
        if cluster_result(i,j)<0

这里cluster_result(i,j)处的值,表示speaker(i)和speaker(j)之间的距离值,例如:cluster_result(1,2)表示speaker1和speaker2之间的距离值。 .现在我从 cluster_result 得到负数,我需要关注

1) 这个负数的索引。 2)然后我想用i替换j,意味着我希望speaker2应该成为speaker1。并且想要创建(或者你可以说替换以前的seg_result矩阵)如下

seg_result=
          start-time   end-time
speaker1  1            10
speaker1  10           25
speaker3  25           43
speaker4  43           end-time of audio wavfile(for ex: 50)

我们将衷心感谢您的帮助...

【问题讨论】:

  • 请更清楚地描述您的问题,您想要的结果应该是什么样的?

标签: matlab matrix


【解决方案1】:

您可以通过以下方式使用find()

negatives= cluster_result<0; % Logical operation, returns a binary matrix with 1 where the expression is true/ exactly equivalent to your loop.

输出:

negatives=
     0     1     0     0
     0     0     0     0
     0     0     0     0
     0     0     0     0

然后使用find() 和两个输出来获取二进制矩阵的非零元素的索引:

[ii,jj]=find(negatives); if you use only one output, you'll get a linear index

输出:

ii =

     1

jj =

     2

现在您有了索引iijj,您可以随意替换和重新排列它们。

希望对您有所帮助。

【讨论】:

  • 感谢您的回复。这很好。我也可以用 ii 替换 jj。但在此之后,请参阅第一个 seg_result 矩阵(在我提出的问题中)应该变成最后一个 seg_result 矩阵(给定在我提出的问题中)...有speaker2被speaker1取代...
  • 这取决于您如何生成矩阵。你能编辑你的问题来解释“seg_result”的样子吗?
猜你喜欢
  • 2015-01-21
  • 1970-01-01
  • 2014-06-08
  • 1970-01-01
  • 2011-12-24
  • 2019-06-01
  • 1970-01-01
  • 2018-03-26
  • 2018-09-09
相关资源
最近更新 更多