Plotting a a constant line in a graph
www.mathworks.com › matlabcentral › answersAug 29, 2014 · plot ( [X (1) X (end), [k k] ) would do the job visually if there isn't a reason you need to have a point for every value of your X time series. Plotting e.g. 1000 points to define a horizontal line is unlikely to result in any kind of performance hit, but is a little un-necessary when 2 points would do just as well.
Vertical line with constant x-value - MATLAB xline
www.mathworks.com › help › matlabAdd a dotted vertical line and label to each plot by passing the axes to the xline function. tiledlayout (2,1) ax1 =nexttile; x = linspace (0,10,200); y1 = cos (x); plot (ax1,x,y1) ax2 = nexttile; y2 = sin (x); plot (ax2,x,y2) xline (ax1,pi/2, ':', 'cos (\pi/2)=0' ); xline (ax2,pi, ':', 'sin (\pi)=0' );
plotting a simple constant - MATLAB & Simulink
www.mathworks.com › matlabcentral › answersSep 17, 2016 · Sometime in your years of using MATLAB you probably ran across ones () function but forgot about it. You need to use it so that, for each value of x, you have a value for Z. Here is the correct way to do it. x = [1 : 0.5 : 10] y = x .* 4. % Now declare a constant array Z. % with one element for each element of x. Z = 4 * ones (1, length (x));