Filter löschen
Filter löschen

Create a step in a graph

1 Ansicht (letzte 30 Tage)
Jórdan Venâncio Leite
Jórdan Venâncio Leite am 31 Mär. 2023
Hi all,
I already have a step up. i wish i had one down. how do i change my code?
aux1=70*1200;
aux2=70.2*1200;
for k=1:aux1
v_aux(k)=0.1;
end
for k=aux1:aux2
v_aux(k)=v_aux(k-1)+(0.3-0.2)/(360);
end
for k=aux2:240000
v_aux(k)=0.31;
end
for k=1:240000
v_aux(k)=v_aux(k)+(rand-0.5)*0.01;
end;
X2=v_aux';
Thanks in advance

Akzeptierte Antwort

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 1 Apr. 2023
In this exercise, no need to use a loop to obtain a step fcn. Way1 is using simple matrix operation:
aux1=70*1200;
aux2=70.2*1200;
X=0.1*ones(1,aux1);
X(70*1200:70.2*1200) =0.1;
X(70*1200:70.2*1200) = X((70*1200)-1:(70.2*1200)-1)+(0.3-0.2)/(360);
X(aux2:240000) = 0.31;
X(1:240000)=X(1:240000)+(rand(1,240000)-0.5)*0.01;
figure
plot(X)
%%
Way 2 is using heaviside() fcn:
syms x
figure
fplot(0.31*heaviside(x - .31), [0, 2]), shg
  1 Kommentar
Jórdan Venâncio Leite
Jórdan Venâncio Leite am 2 Apr. 2023
I wanted the same way as my example, if possible.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graph and Network Algorithms finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by