Number of line for fcontour

2 views (last 30 days)
If somebody can tell me how to increase number of lines for fcontour plot I would be much grateful. Thanks in advance.

Accepted Answer

Star Strider
Star Strider on 27 Nov 2021
A somewhat different approach —
syms x y
z(x,y) = exp(-(x-5)^2) + cos(y)
z(x, y) = 
hfc = fcontour(z, [0 10 -2*pi 2*pi]);
title('Default Levels')
hfc = fcontour(z, [0 10 -2*pi 2*pi]);
Lvls = hfc.LevelList;
hfc.LevelList = linspace(min(Lvls), max(Lvls), 5*numel(Lvls));
title('Increased Countours, Same Range')

More Answers (1)

Image Analyst
Image Analyst on 26 Nov 2021
Look at the max and min of your surface, then compute the 'LevelStep' using the number of contours you want. Something like (untested)
numContours = 10;
levelStep = (max(z(:)) - min(z(:))) / numContours;
fcontour(z, 'LevelStep', levelStep);
  1 Comment
David Togonidze
David Togonidze on 26 Nov 2021
It gives me the error about levelStep not being a double which is logical since I have symbolic expressions in "Z". Shoud have mentioned that in the original question.

Sign in to comment.


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!