Output of a function varies in size for each iteration

1 回表示 (過去 30 日間)
Mir Khadim Aalam
Mir Khadim Aalam 2022 年 5 月 9 日
コメント済み: Mir Khadim Aalam 2022 年 5 月 10 日
I am using the command "strfind" to find indicies where changes in my data occur i.e. my data changes from 0 to 1. For a vector (5400*1) this works fine and it accurateloy finds indices where jump from 0 to 1 takes place. But I have a matrix of size 5400*34, and each of the 34 columns have different places at which the jump of data occurs, for some jump occurs twice, for some once, for others none. The "strfind" command output obviously fails to deal with this problem. Any idea how to solve it?

採用された回答

dpb
dpb 2022 年 5 月 9 日
編集済み: dpb 2022 年 5 月 9 日
Probably as simple a solution as any is to return the indices where the change occurs with both row and column in a form that doesn't depend on the number...unless, of course, there are none globally.
[r,c]=find(diff(A)==1);
NB: You may want to do a "+1" to the above for the row since the difference vector is one element shorter than the original.
You then iterate over the values of c to find the rows for each column for which there is at least one transition as
rows=arrayfun(@(i)r(c==i),unique(c),'UniformOutput',false);
Of course, you can look for any one column as well by
rows=r(c==2);
will be the second column
  1 件のコメント
Mir Khadim Aalam
Mir Khadim Aalam 2022 年 5 月 10 日
worked like a charm, thanks a lot.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by