making a up down ramp

6 次查看(过去 30 天)
Alexander Manderfeld
编辑: Stephan 2020-10-30
For a assignment I am supposed to make a ramp function that goes up plaeteous and then goes back down. My proffesor said use a time array but I do not know what that means. I tried using a peicewise command but that did not work.
  6 个评论
Stephan
Stephan 2020-10-30
Show us what you have done so far and where your specific problem is. Also is there more information about the assignment? Maybe piecewise is not that what your professor wants you to use.
Alexander Manderfeld
profesor finally got back to me and he said it should look like this
t = [0:0.001:5];%
y = zeros(1, length(t));%
index_1 = find(t>0.5 & t<1);%
index_2 = find(t>1 & t<2);
index_3 = find(t>2 & t<2.5);
y(index_1) = 100*t;%
y(index_2) =0.5;
y(index_3)= -100t;
I am still getting error messages
"Unable to perform assignment because the left and right sides have a different number of elements."
not even sure what this code is doing.

请先登录,再进行评论。

采纳的回答

Stephan
Stephan 2020-10-30
编辑:Stephan 2020-10-30
I think you can do the rest by yourself:
t = [0:0.001:5];%
y = zeros(1, length(t));%
index_1 = find(t>0.5 & t<1);%
index_2 = find(t>1 & t<2);
index_3 = find(t>2 & t<2.5);
y(index_1) = 100*t(index_1);%
y(index_2) =0.5;
y(index_3)= -100*t(index_3);
plot(t,y)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by