How do I create several step lines and time delay in a matlab program?

I would like to create a step lines in a plot, also impose a time delay of 10ms. However, when I create the plot, it is only showing one line. Can you tell me if I did something wrong?
Basically, what I am trying to construct is for any t, the Im will be the same as Im will be equal to Iinj. Since Iinj = -1.5:0.5:1.5, I should have 7 step lines in the plot. However, I am not achieving this with this code. I am new to programming, can you help? Thanks.
R = 10;
C = 2;
A = 1;
t = 0:0.03333:0.2;
pause (0.01);
Iinj = -1.5:0.5:1.5;
for i = length(Iinj);
for j = t;
Im = Iinj;
end
end
plot(t, Im(i));

回答(2 个)

try this
close
R = 10; C = 2; A = 1;
ts=0.03333
t = 0:ts:0.2;
Iinj = -1.5:0.5:1.5;
t1=-0.1:ts:0-ts;
t2=0.2+ts:ts:0.2+0.1;
time=[t1 t t2 ]
Im=[zeros(1,length(t1)) t zeros(1,length(t2))]
plot(time, Im);
Thanks Azzi. I am still getting similar result with the above code. What I am hoping to get is from t = 0 to t = 200ms, the Im is the same as Iinj. But before t=0, Im is 0 and after t=200ms, Im is 0 as well. Thanks

1 个评论

is that what you want?
close
R = 10; C = 2; A = 1;
ts=0.03333
t = 0:ts:0.2;
Iinj = -1.5:0.5:1.5;
t1=-0.1:ts:0-ts;
t2=0.2+ts:ts:0.2+0.1;
time=[t1 t t2 ]
Im=[zeros(1,length(t1)) t zeros(1,length(t2))]
plot(time, Im);

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

提问:

2012-9-16

Community Treasure Hunt

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

Start Hunting!

Translated by