How to create a periodic function?
6 views (last 30 days)
Show older comments
Hi everyone,
I have created a function g_3 which looks like:
t=linspace(-2,2);
g_3=[];
for i=1:length(t)
if abs(t(i))<=1
g_3(i)=1-abs(t(i));
else
g_3(i)=0;
end
end
Now I want to do it periodic with periode 4. How can I do it?
3 Comments
Rayan
on 19 Jan 2025
function r = compare_numbers(a,b)
if a>b
r ='greater'
elseif a<b
r ='smaller'
else a==b
r ='equal'
end
Rayan
on 19 Jan 2025
schaltjahre = 1904:4:2000
anzahlJahre = length(schaltjahre)
stunden = 1:24:8760
anzahlStunden = length(stunden)
jahr = 1:364
wochen = reshape(jahr,7,52)'
jahre = 1900:2000
schaltjahre = mod(jahre,4) == 0 & mod(jahre,100) ~= 0 | mod(jahre,400) == 0
schaltjahreidx = jahre(schaltjahre)
eingabe = [10 20 30 40 50 60 70 80 90 100]
a = length(eingabe)
b = a/2
ausgabe = reshape(eingabe,2,b)
eingabe = [10 20 30 40 50 60 70 80 90 100]
jederZweite = eingabe(2:2:end)
jederZweite(end)= NaN
f = 5
t = 0:0.1:10
s = sin(2*pi*f)*t
lastprofile = [1:120]
lp_min = min(lastprofile,[],2)
lp_max = max(lastprofile,[],2 )
lp_diff = lp_max - lp_min
disp(lp_diff)
lastprofile = [1:500]
[lp_min,lp_minIdx] = min(lastprofile)
[lp_max,lp_maxIdx] = max(lastprofile)
lp_diff = lp_max - lp_min
disp(lp_diff)
Lastprofile = [123 4894 213 490 9 4456]
hoch = Lastprofile > 500
niedrig = Lastprofile <= 150
anzahlHoch = nnz (hoch)
anzahlNiedrig = nnz (niedrig)
function win = compare_numbers(a,b)
if a > b
win = 'greater'
elseif a < b
win = 'smaller'
else a == b
win = 'equal'
end
end
Accepted Answer
Ameer Hamza
on 31 Oct 2020
You can use repmat()
t=linspace(-2,2);
g_3=zeros(size(t)); % pre-allocating memory (efficient code)
for i=1:length(t)
if abs(t(i))<=1
g_3(i)=1-abs(t(i));
else
g_3(i)=0;
end
end
G_3 = repmat(g_3, 1, 10);
T = linspace(-2, 4*10, 100*10);
plot(T, G_3)
2 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!