I would like to pick the consecutive cells those satistfies my given condition

I have a array of 122 by 10 data set. I have given the criteria to pick the cells whose values are greather than equal to 1.
Now I would like to pick the cells which satisfies the above condition and those satisfies cells are consecutively aranged.
For Ex: Cell 25,26,27,31 are satisfiying the above creiteria . But I wanted to highligh or list out the greter than or equal to 3 consecutive cells, which mean it has to highlight cell25,26,27

1 Commento

Consecutively along columns? And, to be clear, when you say "cell" you don't really mean a cell array, right?

Accedi per commentare.

 Risposta accettata

You might benefit from downloading,
Then you can label consecutive groups of true elements with, e.g.,
a=rand(1,10)+randi([0,1],1,10)
a = 1×10
0.0060 1.1285 1.2700 0.9325 0.1607 0.3040 0.0583 1.7232 0.4577 1.9700
G=groupTrue(a>1)
G = 1×10
0 1 1 0 0 0 0 2 0 3

9 Commenti

Dear matt,
Thank you, it works .
Here my doubt is can I able to pick those group whose length is greter than 3 alone.
You can use bwareaopen
G = [0 1 1 0 0 0 0 2 0 3 0 4 4 4 4 0 5 5 5]
G = 1×19
0 1 1 0 0 0 0 2 0 3 0 4 4 4 4 0 5 5 5
longerThan3 = bwareaopen(G, 3)
longerThan3 = 1×19 logical array
0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 1 1 1
Or, you can use groupLims from the same File Exchange package, and which doesn't require the Image Processing Toolbox.
G = [1 1 0 0 2 0 3 0 4 4 4 4 0 5 5 5]
G = 1×16
1 1 0 0 2 0 3 0 4 4 4 4 0 5 5 5
[~,~,runlengths]=groupLims(G,1);
G(logical(G))=runlengths(nonzeros(G));
G=groupTrue(G>=3)
G = 1×16
0 0 0 0 0 0 0 0 1 1 1 1 0 2 2 2
Dear Matt,
Thank you very much it works well
Dear Matt,
How can we group multiple conditions ???
For example X=[-1.19 -0.94 -0.78 -0.47 -0.28 -0.22 1.05 1.23 0.78 1.55 1.45 1.00];
From this data I have grouped the values which is >=1 and <=-0.5.
Now I would like to group these two criterias besides a new criteria.
Like wise: Condition 1: I have to get a group where the values <=-0.5 values are more than 3 or= consecutive
Condition 2: Group the cells which values are >=1 more than or = 3 consecutive cells
Condition 3: Group the cells which satisfies the above two criteria in between them.
Answers for each condition:
Condition1: GrpA=[-1.19 -0.94 -0.78]
Condition 2: GrpB=[1.55 1.45 1.00];
Condition 3: GrpC=[ -0.47 -0.28 -0.22 1.05 1.23 0.78];
I want my answer like this :
Tirads =[GrpA GrpC GrpB];
Triadlength=[3 6 3];
Now my function has to pick the above Triads
Can we do this ???
Why wouldn't GrpA be,
X=[-1.19 -0.94 -0.78 -0.47 -0.28 -0.22 1.05 1.23 0.78 1.55 1.45 1.00];
GrpA=X(X<=0.5)
GrpA = 1×6
-1.1900 -0.9400 -0.7800 -0.4700 -0.2800 -0.2200
The Group A criteria is to pick the cells whose values are <= -0.5 and those cells are consecutively arranged.
The above criteria X(X<=-0.5) is picking up wrong values.
How is it wrong? The 6 elements that it returns are indeed consecutively arranged in X.
X=[-1.19 -0.94 -0.78 -0.47 -0.28 -0.22 1.05 1.23 0.78 1.55 1.45 1.00];
X(1:6)<=0.5
ans = 1×6 logical array
1 1 1 1 1 1
It has to pick the values <=-0.5
The above code is picking the values -0.28 -0.22 too.

Accedi per commentare.

Più risposte (0)

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by