How to increase number of contour lines in a plot?
108 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello, could you help me make this plot have 20 controur lines and show their respective values on the plot
f = @(x1,x2) (x1-5)^2+(x2-4)^2;
fcontour(f,[0 10 0 10])
colorbar
0 Kommentare
Antworten (2)
Steven Lord
am 14 Apr. 2022
f = @(x1,x2) (x1-5).^2+(x2-4).^2; % Vectorized the function
h = fcontour(f,[0 10 0 10]); % Let MATLAB choose the number and height of levels
fprintf("There is a contour at level: %g\n", h.LevelList)
figure
h = fcontour(f,[0 10 0 10], 'LevelList', 0:5:50); % I'll choose the levels
fprintf("There is a contour at level: %g\n", h.LevelList)
Bjorn Gustavsson
am 14 Apr. 2022
If you check the documentation you will find this advice:
fcontour(f,'LevelList',[-1 0 1])
which adapted to your xy-region would be something like:
fcontour(f,[0 10 0 10],'LevelList',[-1 0 1])
HTH
2 Kommentare
Bjorn Gustavsson
am 14 Apr. 2022
That is a simple for you to achieve as modifying the levels in the "LevelList". I couldn't be bothered to figure out where to put them since you might want the somewhere else, but for 20 levels between two values you could do something like:
minVal = 0.5; % Still cannot be bothered to find out, so you have do decide.
maxVal = 13; % same as above.
LevelList = linspace(minVal,maxVal,20);
fcontour(f,[0 10 0 10],'LevelList',LevelList)
Siehe auch
Kategorien
Mehr zu Contour Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!