Matlab Question regarding the correct use of contourf

1 次查看(过去 30 天)
Hi everyone,
I have a set of Data that i want to represent in 2D with a third dimesion in color.
Basically I've got the parameters vc and fz with the collected data representing the meassured force.
vc has the values [40 80 120] and fz has the values [0.06 0.12 0.18 0.24 0.30 0.36]. With those two parameters, and some others that are not important right now, i've meassured 360 force values which i want to display.
I've already searched a bit and found a code ( can be found here) which basically does what i would like my plot to do but i've not got it to work, because the vector sizes aren't right or he says the meshgrid isn't right.
To make it work i tried to set the matices to the same size (18x20). Means the Force at [1,1] was generated with vc[1,1] and fz[1,1].
vc
fz
force
I hope you can help me... thanks anyway!

回答(2 个)

Star Strider
Star Strider 2018-4-7
I would plot it as:
figure
contourf(force)
and then define the desired 'XTick' and 'YTick' vectors, and set them as:
xtv = [ ... ];
ytv = [ ... ];
set(gca, 'XTick',xtv, 'YTick',ytv)
You may also need to specify appropriate 'XTickLabel' and 'YTickLabel' values. See the documentation on Axis Properties (link) and specifically Specify Axis Tick Values and Labels (link) for details.
You will need to experiment to get the result you want.
  5 个评论
Steven Lord
Steven Lord 2018-4-10
The error message is correct. The contour object does not have XTick and YTick properties. The axes that contains the contour object does. But you may be able to avoid modifying the ticks yourself; see my answer.
Star Strider
Star Strider 2018-4-10
With respect to the tick labels, use the gca (Get Current Axes) function here:
set(gca, 'XTick',xtv, 'YTick', ytv)
You can also experiment with the xticks, xticklabels, and related functions (introduced in R2016b).
You may not be able to do the interpolation. I am not certain what to suggest for that.

请先登录,再进行评论。


Steven Lord
Steven Lord 2018-4-10
When you call contourf with one input before the number of contours to plot, like contour MATLAB will use the indices as the row and column coordinates. If you specify three inputs before the number of contours, it will use the first two inputs as coordinates instead. Compare these two figures:
>> [x,y,z] = peaks;
>> [c, h] = contourf(x, y, z, 6, 'LineColor', 'k');
>> figure
>> [c2, h2] = contourf(z, 6, 'LineColor', 'k');
If you look at the limits of the axes containing h2, you'll see that the upper limit is 49 (for both X and Y) and the three matrices created by peaks are of size [49 49]. That's not a coincidence.
ax2 = ancestor(h2, 'axes')
If instead you were to look at the limits for the axes containing h, its limits will be from -3 to 3 and those are the min and max values in the x and y matrices.
ax = ancestor(h, 'axes')

类别

Help CenterFile Exchange 中查找有关 Contour Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by