Create a step in a graph

1 view (last 30 days)
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

Accepted Answer

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 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 Comment
Jórdan Venâncio Leite
Jórdan Venâncio Leite on 2 Apr 2023
I wanted the same way as my example, if possible.

Sign in to comment.

More Answers (0)

Categories

Find more on Graph and Network Algorithms in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!