plz explain the code
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
zakir khan
il 28 Set 2018
Modificato: zakir khan
il 28 Set 2018
contour_thres = 0.005;
thres_func = @(x) (x<contour_thres);
0 Commenti
Risposta accettata
ANKUR KUMAR
il 28 Set 2018
contour_thres = 0.005;
asssigning the value in contour_thres
thres_func = @(x) (x<contour_thres);
creating a anonynoms function with the name thres_func which gives logical output. 0 for false and 1 for true. If the input number is less than contour_thres, then its true otherwise it's false
thres_func(5)
using the above defined function. The output of thres_func(5) is 0 as 5 is greater than contour_thres
0 Commenti
Più risposte (1)
Walter Roberson
il 28 Set 2018
The second line is an example of using an anonymous function to parameterize code. At the time the anonymous function is created (not when it is executed!) the current value of the variable contour_thres will be examined and will be stored internally with the anonymous function. Any change to the variable contour_thresh after that will not affect the anonymous function.
So the anonymous function created is one that, given any single input variable, will try to use the < operator appropriate to the variable's data type in order to do a comparison-like operation between the input and the value 0.005 . The formal name of the < operator is lt(), so at the time of execution of the function handle, MATLAB will examine the datatype of the input that it is passed, and will find the gt() function for that datatype, and will execute that gt() passing in x and 0.005 . Typically the input for such a handle would be double precision data type, so typically it would be /Applications/MATLAB_R2018a.app/toolbox/matlab/ops/@double/lt (or equivalent in your installation) that was executed when the anonymous function was invoked.
The meaning of the < operator will depend upon the data type of the input, x, but mostly it is used to signify comparison of values to produce an output of data type logical that is the same size as the input.
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!