drawing a triangular wave

hey guys, what would be the best way to draw a triangular wave?
I just need one triangular wave so my attempt was to draw the left side of the peak of something like y = 2x -8
and right side y = -2x + 8 or something and combine the two, but then I dont know how to make that into one function or graph?

 Respuesta aceptada

Salaheddin Hosseinzadeh
Salaheddin Hosseinzadeh el 8 de Jun. de 2015

0 votos

Hi Soloby,
You just asked a question on fuzzy logic, I assume this is in the same area!
Have you tried trimf or trapmf membership functions?

5 comentarios

soloby
soloby el 8 de Jun. de 2015
i just looked at the help trapmf
it states
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');
what if i just need 1 symmetric triangular wave?
Salaheddin Hosseinzadeh
Salaheddin Hosseinzadeh el 8 de Jun. de 2015
Editada: Salaheddin Hosseinzadeh el 8 de Jun. de 2015
Soloby
You can either use trimf or!!!
do it like this
y1 = trapmf(x,[2 3 3 9]);
To of the numbers in the middle that defines the trapmf should be the same, which indicates the apex of your triangle
soloby
soloby el 8 de Jun. de 2015
I have tried this.
x = 0:10:0.1; f1 = trapmf(x, [2 7 7 9]); f2 = trapmf(x, [2 9 9 18]); plot(x, f1, x, f2)
nothing seems to be showing up in my graph, though? do you know why
Salaheddin Hosseinzadeh
Salaheddin Hosseinzadeh el 8 de Jun. de 2015
Editada: Salaheddin Hosseinzadeh el 8 de Jun. de 2015
you made a mistake defining x
x = 1:0.1:10
not
x = 0:10:0.1 % this is wrong
soloby
soloby el 8 de Jun. de 2015
you're completely right. thank you. I'll ask more on the other question we've been threading. thanks!

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 9 de Jun. de 2015

0 votos

See my attached demo
% Creates triangle waves two ways, one using repmat() and
% one using sawtooth() from the Signal Processing Toolbox.

Categorías

Más información sobre Fuzzy Logic in Simulink en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 8 de Jun. de 2015

Respondida:

el 9 de Jun. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by