Matlab patch: fix the colorscale for a video

4 vues (au cours des 30 derniers jours)
zhang qinghui
zhang qinghui le 9 Juin 2016
Commenté : zhang qinghui le 9 Juin 2016
Hey everyone,
I am blocked with 'patch' function in Matlab for some time. Any help will be strongly appreciated.
So I am using the 'patch' function to plot numerical results at different time steps, based on a triangle mesh. If I use the function below:
h = patch('Faces',m.IKLE, 'Vertices', m.XYZ,'FaceVertexCData',m.RESULT(:,3), 'Facecolor', 'interp','EdgeColor','black','linewidth',0.01 );
where 'm' is a structural object that I have created; inside it includes faces and vertices information, also the data that I would like to plot, here shows m.Result(:,3), meaning the result at time step 3. However, if I want to plot all results of different time steps in order to create a video, the Matlab function will call this at each time step. The problem is, the colorscale keeps changing. For example, at time 1, the value ranges from 1 to 2, then 1 may be red, and 2 may be green. But at time 2, the value may range from 1 to 10, then at this time, 10 is green. I would like to write a small program, to detect the largest and smallest value that can ever occur, then fix a colormap to this range. Does anyone have any idea about how to fix the mapping step? Say, I want to fix, 1 to red, 10 to green, the middile values and colors to be interpolated. Then this colorscale will be used for each time step.
Thank you very much and hope you have a good day!
Qinghui

Réponse acceptée

Walter Roberson
Walter Roberson le 9 Juin 2016
Set the patch CDataMapping property to 'direct'. The FaceVertexCData value will then be used as an index into the colormap.
You could construct a custom colormap with 10 entries, one for each of the values you want to define. If that does not give you a high enough resolution, you could multiply the input m.RESULT(:,3) by N/10 where N is the number of colors in your color map .
Alternately, you can continue to use the default CDataMapping of 'scaled' and use caxis([1 10])
  1 commentaire
zhang qinghui
zhang qinghui le 9 Juin 2016
That's very kind of you! Thank you very much and I am going to try!
Greetings,
Have a good day!
Qinghui

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

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