1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
Description: Update anonymous function to be a single statement call to nested function
Origin: upstream, https://sourceforge.net/p/octave/fuzzy-logic-toolkit/ci/00e05af94b3762d2e051ad28fb436da089160f40/
Bug: https://savannah.gnu.org/bugs/?53549
Last-Update: 2018-05-12
--- octave-fuzzy-logic-toolkit-0.4.5.orig/inst/defuzz.m
+++ octave-fuzzy-logic-toolkit-0.4.5/inst/defuzz.m
@@ -1,4 +1,4 @@
-## Copyright (C) 2011-2014 L. Markowsky <lmarkov@users.sourceforge.net>
+## Copyright (C) 2011-2018 L. Markowsky <lmarkov@users.sourceforge.net>
##
## This file is part of the fuzzy-logic-toolkit.
##
@@ -162,7 +162,16 @@ endfunction
function crisp_x = mom (x, y)
max_y = max (y);
- y_val = @(y_val) if (y_val == max_y) 1 else 0 endif;
+
+ function y_val = calc_yval(y_val)
+ if (y_val == max_y)
+ y_val = 1;
+ else
+ y_val = 0;
+ endif
+ endfunction
+
+ y_val = @(y_val) calc_yval(y_val);
max_y_locations = arrayfun (y_val, y);
crisp_x = sum (x .* max_y_locations) / sum (max_y_locations);
@@ -185,7 +194,16 @@ endfunction
function crisp_x = som (x, y)
max_y = max (y);
- y_val = @(y_val) if (y_val == max_y) 1 else (NaN) endif;
+
+ function y_val = calc_yval(y_val)
+ if (y_val == max_y)
+ y_val = 1;
+ else
+ y_val = (NaN);
+ endif
+ endfunction
+
+ y_val = @(y_val) calc_yval(y_val);
max_y_locations = arrayfun (y_val, y);
crisp_x = min (x .* max_y_locations);
@@ -207,7 +225,16 @@ endfunction
function crisp_x = lom (x, y)
max_y = max (y);
- y_val = @(y_val) if (y_val == max_y) 1 else (NaN) endif;
+
+ function y_val = calc_yval(y_val)
+ if (y_val == max_y)
+ y_val = 1;
+ else
+ y_val = (NaN);
+ endif
+ endfunction
+
+ y_val = @(y_val) calc_yval(y_val);
max_y_locations = arrayfun (y_val, y);
crisp_x = max (x .* max_y_locations);
|