How to plot 4D contourf for the matrix C(40*40) with respect to A(40*40) as x axis and B(40*40) as y axis for different levels z=1000, 800, 600, 400 in one plot?
1 view (last 30 days)
Show older comments
Dear Sir I have three matrices A,B and C having same size 40*40. I want to plot a contour of C(40*40) taking A(40*40) as x axis and B(40*40) as y axis for different levels z=1000, 800, 600, 400 in one plot. Please help.
0 Comments
Accepted Answer
Walter Roberson
on 19 Sep 2015
If your X and Y data are sorted in a good grid, then
contourf(X, Y, C, [400, 600, 800, 1000])
If your X and Y are not sortable to a good grid then you will need to do some grid interpolation and contour that.
11 Comments
Walter Roberson
on 21 Sep 2015
This was tricky to figure out.
I have enclosed a file patchfill.m which can be used for this purpose. This is for HG1 (Handle Graphics 1) only in its present form (I do not have an HG2 version to experiment with.) Beware: R2014b and later (HG2) represent contours a different way!
[~, h] = contour3(X1, Y1, C1);
hold on
patchfill(h, 400);
[~, h] = contour3(X2, Y2, C2);
patchfill(h, 600);
[~, h] = contour3(X3, Y3, C3);
patchfill(h, 800);
[~, h] = contour3(X4, Y4, C4);
patchfill(h, 1000);
The patchfill routine I provide does two things:
- alters the patch() properties returned by contour3 to allow the contours to fill. The contours returned by contour3 (in HG1) are deliberately configured to make it hard to turn on filling.
- sets the Z values to the value passed in, if one is passed in.
More Answers (0)
See Also
Categories
Find more on Contour Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!