MATLAB: Specify axis limit to be nonneagtive MATLAB https://www.mathworks.com/help/matlab/creating_plots/change-axis-limits-of-graph.html discusses controling where data appears in the axes by setting the x-axis, y-axis, and z-axis limits. Then, how can I set the y axis to be nonnegative (but doe not set the upper limit)? Best Answer You can set the upper limit to Inf to let MATLAB automatically thataxis([0 inf 0 inf 0 inf])orxlim([0 inf])ylim([0 inf])zlim([0 inf]) Related SolutionsMATLAB: Efficiently setting lower axis limit One line:set(gca, 'XLim', [0, get(gca, 'XLim') * [0; 1]])Or without assuming that the lower limit is 0:set(gca, 'XLim', get(gca, 'XLim') .* [0, 1] + [lowLimit, 0])But your three lines are easier to read and faster to debug. MATLAB: Plot only for positive y NEW ANSWER ylim([0 inf]) %Will automatically compute the limit where "inf" is used OLD ANSWER ylim([0, max([y(:); z(:); w(:)])) %will plot positive values of y axis from 0 to the maximum of either your y or z or w values. Related QuestionPlotyy – Managing the colors of y-labelsMultiple X-Axes with separate scales and xlabelsHow to modify the Y limits of the axes created by PLOTYY in the MATLAB figure
Best Answer