Effacer les filtres
Effacer les filtres

How to make a contour plot with incomplete z data?

8 vues (au cours des 30 derniers jours)
Onur Kucuktas
Onur Kucuktas le 5 Nov 2021
Modifié(e) : Chris le 6 Nov 2021
I have a collection of intersection points of a square plane. Each intersection point has an intensity associated with it (doing light ray tracing). I need the intensity to be the elevation of the contour plot, and the points to be the x and y respectively. Areas not intersected by any rays need to have an elevation of zero. I have a vector that has x values of intersection, a vector that has y values of intersection, and a vector that has intensities. I'm not sure how to make a contour plot using this information. Using the contourf function with those vectors as an input says that Z must be at least a 2x2 matrix, and I don't know how to form this matrix when basically any point that isn't included needs to have an elevation of 0. Any guidance is appreciated!

Réponses (1)

Chris
Chris le 5 Nov 2021
Modifié(e) : Chris le 6 Nov 2021
As far as I understand, you'll need a rectangular array representing the grid of intensity values. If your grid is square and your vector contains all the points, that could be as simple as a reshape() operation. Adapting the first example from the contour documentation, you can either set all the zero points to NaN or to 0, to different effect:
xvec = linspace(-2*pi,2*pi);
yvec = linspace(0,4*pi);
[X,Y] = meshgrid(xvec,yvec);
Z = sin(X)+cos(Y);
Z(randi(100,50,1),randi(100,50,1)) = 0;
contourf(X,Y,Z)
Z(Z==0) = nan;
contourf(X,Y,Z)
In this example the contours ignore the NaNs. In the previous, they drop to zero.
Does that help, or does it need more clarification?

Catégories

En savoir plus sur Contour Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by