Matlab contourf
If I'm asked to plot a function S with "level lines" abs(S) = 0:0.1:1, how do I do that?
I looked up the solution:
[X,Y] = meshgrid(-15:0.1:15);
Z = X + i*Y;
contourf(X,Y,abs(S),[1 1]);
where they pass in the fourth开发者_运维知识库 argument [1 1] but I've no idea what it's doing. Why do they pass in [1 1] if they ask me for lines between 0 and 1?
Any help is much appreciated!
They're making a mistake.
The help to contourf
states
To draw a single contour of level i, use contour(Z,[i i])
So they're drawing a single contour line at 1.
You want to write
contourf(X,Y,abs(S),0:0.1:1);
because the help says
contourf(Z,v) draws a filled contour plot of matrix Z with contour lines at the data values specified in the monotonically increasing vector v. The number of contour levels is equal to length(v)
精彩评论