imagesc, HeatMap or something else with non-rectangular cells
Mostrar comentarios más antiguos
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!
Respuesta aceptada
Más respuestas (1)
Mike Garrity
el 1 de Feb. de 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 comentarios
janklab
el 2 de Feb. de 2016
Mike Garrity
el 2 de Feb. de 2016
Just ask for an output argument:
x = hot(64)
Categorías
Más información sobre Data Distribution Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!