필터 지우기
필터 지우기

imagesc, HeatMap or something else with non-rectangular cells

조회 수: 3 (최근 30일)
janklab
janklab 2016년 2월 1일
댓글: Mike Garrity 2016년 2월 2일
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!

채택된 답변

Image Analyst
Image Analyst 2016년 2월 1일
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
janklab
janklab 2016년 2월 2일
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 2016년 2월 2일
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);

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Mike Garrity
Mike Garrity 2016년 2월 1일
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
janklab
janklab 2016년 2월 2일
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 2016년 2월 2일
Just ask for an output argument:
x = hot(64)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by