MATLAB Answers

# Plot only for positive y

268 views (last 30 days)
alpedhuez on 12 Jun 2018
Edited: OCDER on 13 Jun 2018
I have
plot(x,y)
hold on
plot(x,z)
hold on
plot(x,w)
I need to have a plot for only positive y and z. I try to write
ylim([0,yMax])
But I do not know how to set for yMax. Please advise.

#### 2 Comments

OCDER on 12 Jun 2018
ylim([0,max(y)])
?
Curious, why do you have to plot(x, z) twice? Also, do you want to plot the maximum of y or z?
ylim([0, max([y(:); z(:)]))
alpedhuez on 12 Jun 2018
I have sought a simpler way to specify Y axis so that the figure only shows positive part of the Y-axis.

Sign in to comment.

### Accepted Answer

OCDER on 12 Jun 2018
Edited: OCDER on 13 Jun 2018
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.

#### 2 Comments

alpedhuez on 12 Jun 2018
would be efficient that a future version has an option for ylim that automatically calculates maxes of all the y-axis variables.
OCDER on 13 Jun 2018
Actually, there was an easier solution. I'll update the answer:
ylim([0 inf]) %will automatically compute the limit where "inf" is used

Sign in to comment.

### More Answers (0)

Sign in to answer this question.