Effacer les filtres
Effacer les filtres

imagesc, HeatMap or something else with non-rectangular cells

3 vues (au cours des 30 derniers jours)
janklab
janklab le 1 Fév 2016
Commenté : Mike Garrity le 2 Fév 2016
Is it possible in the function imagesc or HeatMap to create a color-figure without rectangular cells, but with cells with customized shape (in this case triangular)? Or is there another function which can do this?
Imagine a car driving with varying speed, but its speed is constant during a time step of 5 seconds, thus between 0 and 5 seconds it has some constant speed, between 5 and 10 it has another constant speed, and so on. Its location x1(t) with t in [a,a+5] can be determined from x1(t) = x1(a)+ t*v1(a). Now, there also is a second car (always behind the first one) with location x2(t): x2(t) = x2(a)+t*v2(a). Again, the second car has constant speed in a time interval of 5 seconds. For both cars we have a trajectory in the (t,x)-plane. Sometimes the second car gets closer to the first car and sometimes it gets further away. Hence, the difference x1(t) - x2(t) is not constant (it is a linear function).
Now, I want to assign a color to x1(t) - x2(t). The bigger x1(t) - x2(t), the darker the color should be (for example). So considering the (t,x)-plane it contains two trajectories (x1, x2) and between those trajectories there should be colors indicating the differences x1(t) - x2(t).
Is there a function in MATLAB which can do this? I was thinking about imagesc or heatmap, but they only work with colors in rectangular cells as far as I know.
Thanks in advance!

Réponse acceptée

Image Analyst
Image Analyst le 1 Fév 2016
This seems like a 1-D situation -- x vs. t -- not a 2D situation. How about if you plot x1 and x2 vs. t, and have something, such as the area between the curves shaded with patch() or fill() according to the difference between the curves (like according to the area difference between two times)?
  4 commentaires
janklab
janklab le 2 Fév 2016
I managed to do it with the patch() function. On a side note, where can I find the colors in the colormap 'hot'? I mean the RGB [x y z] codes
Image Analyst
Image Analyst le 2 Fév 2016
Just type "hot" or "hot(256)" in the command line to see a listing of all the RGB colors. You can assign it to a variable if you want.
rgbValuesOfHot = hot(256);

Connectez-vous pour commenter.

Plus de réponses (1)

Mike Garrity
Mike Garrity le 1 Fév 2016
You can do heatmap like things with triangular meshes, but there is a bit of a learning curve. You're going to want to learn about Triangulation.
Here's a simple example. I'm using delaunayTriangulation because it will generate the triangles for me, but you might want to define your own ConnectivityList.
x = 2*randn(100,1);
y = 2*randn(100,1);
dt = delaunayTriangulation(x,y);
Now I can use the trisurf function to draw a color at each vertex and interpolate across the interior of the triangles.
c = cos(x).*cos(y);
z = zeros(100,1);
trisurf(dt.ConnectivityList,x,y,z,c,'FaceColor','interp')
view(2)
I could also have one color for each triangle.
c = dt.circumcenter;
c = cos(c(:,1)) .* cos(c(:,2));
z = zeros(100,1);
trisurf(dt.ConnectivityList,x,y,z,c,'FaceColor','flat')
view(2)
  2 commentaires
janklab
janklab le 2 Fév 2016
Thank you for your explanation! But I managed to do it with the patch() function. On a side note, where can I find the colors in the colormap 'hot'? I mean the RGB [x y z] codes.
Mike Garrity
Mike Garrity le 2 Fév 2016
Just ask for an output argument:
x = hot(64)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Distribution 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