About the use of find

I want to detect values greater than 10 and get their indices.
In my case, I'm using find to get the index as follows.
y = find( x > 10 );
I think find is finding the value greater than 10 in all elements of x and getting the index.
So I have a question.
Does find start computing at the moment when all the elements of x are given, rather than at the moment when any element of x is given?
I would like to perform the computation at the moment when even one element of x is given, do the same process as find, get the same index, and store it in the same way.
In that case, what kind of program should I write? It would be great if you could post your program.

4 commentaires

Yazan
Yazan le 23 Août 2021
Modifié(e) : Yazan le 23 Août 2021
Does find start computing at the moment when all the elements of x are given...
The function find can work even with empty matrices.
find([]>10)
ans = []
As you see, the result is an empty array, because no element in an empty array is larger than 10 obviously.
% No element is larger than 10
x = [1 2];
find(x>10)
ans = 1×0 empty double row vector
% x now has one new element, it is larger than 10 indeed, and it is the
% element of index 3, so find will return the value 3
x = [1 2 12];
find(x>10)
ans = 3
I would like to perform the computation at the moment when even one element of x is given, do the same process as find, get the same index, and store it in the same way.
What does this mean? You want to replicate what find is doing using your own code or what?
Stephen23
Stephen23 le 23 Août 2021
Modifié(e) : Stephen23 le 23 Août 2021
"I think find is finding the value greater than 10 in all elements of x and getting the index."
No. That logical comparison identifies all values of x greater than 10, and returns the corresponding logical array.
Find then just returns the linear/subscript indices of that logical array (which is why logical indexing is faster, because it simply avoids this second step entirely).
"Does find start computing at the moment when all the elements of x are given, rather than at the moment when any element of x is given?"
What exactly does that mean? What is a "given" element, how is it distinguished from a not "given" element?
Please give an example of a MATLAB array where some element is "given" but some other elements are not "given".
A
A le 23 Août 2021
Modifié(e) : A le 23 Août 2021
Dear Yazan
Thank you for your answer.
I am sorry that my questions are poorly written and difficult to understand.
In this case, I'm considering the data to be obtained from the simulink in real time as x.
In that case, will find calculate the value of x in real time?
Or does it start calculating after the simulink simulation is finished and all the data for x is ready?
I would like to perform the computation at the moment when even one element of x is given, do the same process as find, get the same index, and store it in the same way.
Regarding the above question...
"How can I write a program that does the same thing as find, but computes it in real time?
A
A le 23 Août 2021
Dear Stephen Cobeldick
Thank you for your answer.
I learned that find returns the linear/subscript index of the logical array.
If I want to get the linear/subscript index of a logical array, is there any other way than find?
I am sorry that my questions are poorly written and difficult to understand.
"Does find start computing at the moment when all the elements of x are given, rather than at the moment when any element of x is given"
Regarding the above question...
In this case, we run Simulink and consider the data to be acquired in real time as x.
In this case, does find calculate the value of x in real time?
Or does it start calculating after the Simulink simulation is finished and all the data for x is available?
As for the array example, here's what the workspace looks like after a Simulink simulation.
It may be difficult to understand...

Connectez-vous pour commenter.

Réponses (1)

Wan Ji
Wan Ji le 23 Août 2021

0 votes

Find is not at all faster than logical inices.
IF you know how to use logical indices to get elements from matrix. I believe you will like it.
A = [true, false, true, false]; % logical inices
B = [4,3,5,6];
B(A) % this gets the value in B corresponds to true element in A
Then
ans =
4 5
But find should have such a following process
p = find(A);
B(p)
Also,
ans =
4 5
Find sometimes can be implemented by
n = 1:1:length(A);
p = n(A)
Then
p =
1 3

1 commentaire

A
A le 23 Août 2021
Thank you for your answer, and thank you for writing the program that turns into find.
Also, I apologize for my bad way of asking the question, it is not so clear.
In this case, I think x is the data to be retrieved from the simulator in real time.
In this case, is it still possible to detect x greater than 10 with the program you taught me?
I would be glad if you could answer me again.

Connectez-vous pour commenter.

Produits

Version

R2021a

Question posée :

A
A
le 23 Août 2021

Commenté :

A
A
le 23 Août 2021

Community Treasure Hunt

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

Start Hunting!

Translated by