Create a step in a graph

1 次查看(过去 30 天)
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

采纳的回答

Sulaymon Eshkabilov
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graph and Network Algorithms 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by