Create a triangular wave/sawtooth function.

8 views (last 30 days)
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

Answers (1)

reen2015
reen2015 on 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

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!