Output of a function varies in size for each iteration

2 views (last 30 days)
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?

Accepted Answer

dpb
dpb on 9 May 2022
Edited: dpb on 9 May 2022
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

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by