How to use find command for non-integer array?

9 views (last 30 days)
This is my algorithm, but the problem is "corrl" and "threshold" are non-integer arrays, and resulted in empty matrix. Is there any other alternative to find the same problem??
[dmin,tmin]=find(corrl<-threshold)
[dmax,tmax]=find(corrl>threshold)
  2 Comments
Dyuman Joshi
Dyuman Joshi on 20 Mar 2023
Edited: Dyuman Joshi on 20 Mar 2023
There is no relation between the arrays being non-integer and the result being empty matrix. The functionality of find() is the same for all numeric data types. The result corresponds to the condition(s) satisfied.
Are all values in threshold and corrl positive? If yes, then the first condition will never be satisfied, and thus the output will be an empty matrix.
It's difficult to say about the second condition without any data. Please attach your data using the paperclip icon.
DGM
DGM on 20 Mar 2023
The fact that the arrays are non-integer shouldn't be an issue unless you're trying to test for equality (or near-equality) conditions, which you aren't.
x = randn(1,10)
x = 1×10
0.4572 -0.3947 0.7026 1.7829 1.1731 0.9493 -1.1451 -0.7009 -0.9586 -0.1771
thresh = 0.01*ones(size(x));
[r1 c1] = find(x<-thresh)
r1 = 1×5
1 1 1 1 1
c1 = 1×5
2 7 8 9 10
[r2 c2] = find(x>thresh)
r2 = 1×5
1 1 1 1 1
c2 = 1×5
1 3 4 5 6
Without knowing what ether array look like, I'd have to guess that the conditions simply aren't being met. What is the output of
nnz(corrl>threshold)
If it's zero, then there are no matches.

Sign in to comment.

Answers (1)

Sugandhi
Sugandhi on 20 Mar 2023
Hi Rahul,
I understand that you are trying to get row and column subscripts of each nonzero element after comparing corrl and threshold arrays whose elements are non - integers.
It results in empty matrix because no pair is satisfying the relational condition i.e., every pair return 0.
Go through this example:
v1 = [0.55 2.32;0.42 1.89];
v2 = [0.34 ;0.22];
res= v1<-v2
res = 2×2 logical array
0 0 0 0
[x1,y1]=find(v1<-v2)
x1 = 0×1 empty double column vector y1 = 0×1 empty double column vector
[x2,y2]=find(v1>v2)
x2 = 4×1
1 2 1 2
y2 = 4×1
1 1 2 2
For more understanding kindly go through the following link –

Community Treasure Hunt

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

Start Hunting!