how to shift a step-plot(input)
1 view (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Image Analyst
on 4 Mar 2016
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
0 Comments
More Answers (1)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!