error with the trapmf function

6 visualizzazioni (ultimi 30 giorni)
Ameri
Ameri il 20 Nov 2022
Commentato: Ameri il 21 Nov 2022
Dear Sir/ Madam
I would like to ask for a sloution fot this problem please.
What should I do? Thank you

Risposta accettata

John D'Errico
John D'Errico il 20 Nov 2022
You wrote this:
x1 = 0:1:25;
y1 = trapmf(x, [0 5 15 25]) ;
Unrecognized function or variable 'x'.
So you created the variable x1. Then you called the function trapmf. What is x? Should MATLAB somehow know what it should do here? What is x? Should it read your mind, that somehow, it should know that MAYBE, you wanted to pass in x1, instead of the undefined variable x?
Software does what you tell it to do. It does not read your mind.
  3 Commenti
John D'Errico
John D'Errico il 21 Nov 2022
Why would it not be tilted? First, what is trapmf?
help trapmf
TRAPMF Trapezoidal membership function. TRAPMF(X, PARAMS) returns a matrix which is the trapezoidal membership function evaluated at X. PARAMS = [A B C D] is a 4-element vector that determines the break points of this membership function. We require that A <= B and C <= D. If B >= C, this membership function becomes a triangular membership function that could have a height less than unity. (See the example below.) For example: x = (0:0.1:10)'; y1 = trapmf(x, [2 3 7 9]); y2 = trapmf(x, [3 4 6 8]); y3 = trapmf(x, [4 5 5 7]); y4 = trapmf(x, [5 6 4 6]); plot(x, [y1 y2 y3 y4]); set(gcf, 'name', 'trapmf', 'numbertitle', 'off'); See also DSIGMF, EVALMF, GAUSS2MF, GAUSSMF, GBELLMF, PIMF, PSIGMF, SIGMF, SMF, TRIMF, ZMF, LINSMF, LINZMF. Documentation for trapmf doc trapmf
Ok a trapezoid.
x1 = 0:1:25;
y1 = trapmf(x1, [0 5 15 25]);
plot(x1,y1)
So, a trapezoid, where the top edge is not centered. Where does that top live? It is completely controlled by the second and third break points, and where they lie, compared to the first and 4th breakpoint.
Note that the distance from 0 to 5, is NOT the same as the distance from 15 to 25.
Would you expect the result to be symmetrical? Again, computers follow your orders. They do what you tell them to do.
If you insist on symmetry, then you need to choose a set of breakpoints that would be symmetrical. Ergo, you might decide to adjust one of the numbers 5, 15 or 25 in that call. Where you want to put them is your choice. For example, what would happen if you used [0 5 20 25] as the second argument to trapmf?
Ameri
Ameri il 21 Nov 2022
Thank you so much for your response. I have changed the distance from 15 to 25. To be 20 25 and now looks fine. Many thanks

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Fuzzy Logic Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by