Create a triangular wave/sawtooth function.

9 visualizzazioni (ultimi 30 giorni)
Alejandro Urbina
Alejandro Urbina il 10 Apr 2016
Commentato: Chad Greene il 11 Apr 2016
I have been trying to graph a triangular wave,sawtooth function on math lab r2015a i have been the example code from their website
T = 10*(1/50); Fs = 1000; dt = 1/Fs; t = 0:dt:T-dt; x = sawtooth(2*pi*50*t);
plot(t,x);
but it dose3nt run...
i tried to make my own code to graph a regular line mx+b and get the absolute value of the function to let it repeat over all the t values and make the same result and limit the max value to 1
t = linspace(-2,2,1e4); % time vector [s] x = zeros(size(t)); % this creates a vector of zeros the same size % as the vector t x(mod(abs(t),2) < 1 | mod(abs(t),2) > 0 ) = 1;
tmin = min(t); tmax = max(t); xmin = -0.2; xmax = 1.2; plot(t,x); axis([tmin tmax xmin xmax]);
this is just graphing a regular line all...
i know im doing some lame mistake and thats why the code is not running in either cases... ill appreciate any type of help to make this run... thank you
  2 Commenti
Chad Greene
Chad Greene il 10 Apr 2016
Seems to create a sawtooth for me.
Alejandro Urbina
Alejandro Urbina il 11 Apr 2016
this is what matlab is telling me...

Accedi per commentare.

Risposte (1)

reen2015
reen2015 il 11 Apr 2016
I think its because you have saved the file with name sawtooth, which is mattlab function name.
try saving using different name.. such as mysaw.m
the code below that you posted creates sawtooth even if you paste in caommand window
T = 10*(1/50); Fs = 1000; dt = 1/Fs; t = 0:dt:T-dt; x = sawtooth(2*pi*50*t);
plot(t,x);
good luck
raina

Categorie

Scopri di più su Programming 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