Comet command - change colour and speed

16 visualizaciones (últimos 30 días)
Pravin Karthick Murugesan
Pravin Karthick Murugesan el 13 de Mzo. de 2019
Editada: DGM el 27 de Ag. de 2025
Hey guys!
Is there a way to change the colour and speed properties of the comet command ?
Any help is appreciated.

Respuestas (2)

Keyhan Kouhkiloui
Keyhan Kouhkiloui el 22 de Abr. de 2019
Editada: Keyhan Kouhkiloui el 22 de Abr. de 2019
Hey, Hi,
I found one easy way of changing the colour property in comet command. Copy and past the comet script in the folder that you have your data and rename it.
Go to the script of comet (renamed by you), just simply go to line representing the << if size(co,1)>=3 >> and replace: colors = [ co(1,:);co(2,:);co(3,:)]; with colors = [ 'r';'b';'g']; in the following line. (I used red, blue and green for my personal performance of the comet command, you can change it to any color supported by MATLAB in the following link: https://uk.mathworks.com/help/matlab/ref/colorspec.html)
I am still working on finding a way to put maybe time delay in the windows updating process, as drawnow is a built-in command in MATLAB. I'd let you know if I could find a reasonable way of doing it.

DGM
DGM el 27 de Ag. de 2025
Editada: DGM el 27 de Ag. de 2025
The comet() function takes its colors from the axes 'colororder' property. If the colororder has at least 3 entries, it uses them for the graduation; otherwise, it simply uses the first entry.
It's limited, but that does give us a way to set the color of a comet that doesn't require modifying the comet() code or learning how to write an efficient plot() loop. Simply set the axes colororder.
% some fake data
x = linspace(-5,5,100);
y = sin(x);
% let's say we had some things in the axes to begin with
% note how the color is being assigned here
plot(x,y,'r'); hold on; grid on
plot(x,5*y,'k');
% temporarily set the custom colororder
set(gca,'colororder',[0.8 0.2 1]); % 1x3 or 3x3 color table
% plot the comet
comet(x,x.*y);
Obviously, the animation doesn't work on the forum, but you can tell it's not the expected yellow color anymore. Note that there are limitations to doing things this way. The setup here is deliberate. The axes needs to be configured prior to calling comet(), otherwise our custom colororder won't be used. In fact, it seems quite difficult to get comet() to actually pick up the axes colororder any other way.
In this example, I simply drew some other curves using plot() in a manner which presets the desired axes limits. Note that I explicitly set the colors of these objects. If I had called plot() without this colorspec, these objects would derive their color from the axes colororder, and would be subject to change when we assert our custom color.
In practice, this is all a very ugly way to do it, but it can be succinct and perfectly adequate in some cases. For example, I came up with this workaround when using comet() to highlight directed edges of a triangulated 2D mesh drawn using patch(). Since the patch() object is drawn first, it configures the axes, and since it doesn't rely on the colororder, it doesn't pose a problem.
Other than that, the choices are the same as they were before. Either modify a copy of comet(), write a clean loop updating plot(), or use animatedline.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by