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

Ameer Hamza
Ameer Hamza 2020년 10월 30일
Can you show what have you already tried?
Adam Danz
Adam Danz 2020년 10월 30일
You're describing a step function which can be plotted several ways. Step functions have duplicate x-values when the function steps upward or downward making them easy to create using a simple plot() command. You could also use Matlab's heaviside() function or step().
Alexander Manderfeld
Alexander Manderfeld 2020년 10월 30일
I have tried making it a peicewise function with that command and it did not work. I do not want a step function, it needs to have a positive slope at the beggining plaeteuo in the middle and the a negative slope back down. Going straight up then striaght back down like a step will not work.
Adam Danz
Adam Danz 2020년 10월 30일
That's even easier.
By the way, I can assure you the functions I mentioned early work. I think what you mean is that you tried the functions but they didn't achieve the trapezoidal changes you described in the comment above.
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.
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일

0 개 추천

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개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

태그

질문:

2020년 10월 30일

편집:

2020년 10월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by