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 Kommentare

Rayan
Rayan am 19 Jan. 2025
[lp_min,lp_minIdx]=min(lp)
[lp_max,lp_maxIdx]=max(lp)
lp_diff=lpmax-lpmin
disp(lp_diff)
hoch=lastprofile>500
niedrig=lastprofile<=150
anzahlHoch=nnz(hoch)
anzahlNiedrig=nnz(niedrig)
[c,S,mu]=polyfit(x,y,11)
xNeu=570:670
yNeu=polyval(c,xNeu,S,mu)
yNeu=yNeu(:)'
Rayan
Rayan am 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
Rayan am 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

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 31 Okt. 2020

1 Stimme

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 Kommentare

Klaudjo Aliaj
Klaudjo Aliaj am 3 Nov. 2020
Thank you very much, that´s exactly what I was looking for :)
Ameer Hamza
Ameer Hamza am 3 Nov. 2020
I am glad to be of help!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!