how to shift a step-plot(input)

1 次查看(过去 30 天)
Hello. I am struggeling with Matlab. My knowledge about it, is very limited. Let me introduce myself. My name is Bob,this year i am following a course digital control and this is the first year that i am confronted with Matlab. I want to shift only the step-plot(grey line) 0,25 seconds to the left so that the step wil begin at zero in stead of 0,25seconds. For clarity, the vertical part of the grey line must begin at zero in stead of 0,25sec. First i tried to subtract 0,25 from tsample in line 17--->"plot(tsample-0,25,input,'b')" But that does not work. Then I tried something with "circshift" but without result. I think it must be done in line 17 or before it. In the appendix you can find the .m file and .mat file to run the plot.(you can ignore the bode-plot). So how can i shift the grey input-line(step) with 0,25seconds to the the left?? Thank you in advance.

采纳的回答

Image Analyst
Image Analyst 2016-3-4
Bob, don't use input for the name of your "y" variable because it's the name of a build in function. To shift the y values to the left or right, you should generate a new y array and then plot it. Try something like this:
x = 0 : 40;
y = GetY(x); % Get original y
% Plot original y
plot(x, y, 'b*-', 'LineWidth', 2);
grid on;
hold on;
% Get a new y for a shifted x
% Pass in x that has a number subtracted from it.
y2 = GetY(x-10);
% Plot new, shifted y
plot(x, y2, 'rd-', 'LineWidth', 2);
function y = GetY(x)
y = x > 20; % Step function

更多回答(1 个)

bob de vrij
bob de vrij 2016-3-5
Thank you image analyst for the quick response. I will make an attempt in the evening.

类别

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