4 views (last 30 days)

I have temp vs time data for 100 points along a circle.

I would like create a small animation of the temp vs time basedon colour of the circle.

(If not a circle I would atleast like to try it along a line. )

Is it possible somehow?

A sample/Example would be like this

This has 6 frames, with the color representing the temperature and frames representing the passage of time.

Here it is made as a contiuous diagram, with smooth gradients. If it is not possible, is it possible as discreet sections of a circle.

Kelly Kearney
on 26 May 2020

It's not clear to me whether you've already created the circle plots in Matlab, or if you just sketched out your desire outcome.

If you haven't plotted them yet, I think using a simple patch is the easiest way to achieve that look. To animate, it depends on whether you just want to animate on screen or export to something like a gif. The example below shows the former.

% Some example data

t = linspace(0,1,100)'; % time coordinate, normalized

data = rand(100,3); % three time steps of random data

% Use patch to plot the circle

th = 2*pi*t;

rmin = 0.8; % inner radius

rmax = 1; % outer radius

xouter = rmax.*cos(th);

xinner = rmin.*cos(th);

youter = rmax.*sin(th);

yinner = rmin.*sin(th);

x = [xouter; xinner(end:-1:1); xouter(1)];

y = [youter; yinner(end:-1:1); youter(1)];

c = [data; data(end:-1:1,:); data(1,:)];

axes

p = patch(x,y,c(:,1));

axis equal;

set(gca, 'visible', 'off');

set(p, 'edgecolor', 'none');

% Loop over to animate

for it = 2:size(data,2)

pause(1);

set(p, 'cdata', c(:,it));

end

Kelly Kearney
on 29 May 2020

Here's the example again, this time with your data and more comments:

% Your data

tmp = readtable('~/Downloads/10Sec - Copy.xls');

data = table2array(tmp(:,2:end))'; % sector x time array

sector = 1:size(data,1); % sector, 1,2,...20

% Step 1: upsample your data. This isn't strictly necessary but will allow

% your ring to look more like a circle than a 20-gon

secup = linspace(1,20,100)';

data = interp1(sector, data, secup); % new higher-res sector x time array

% Step 2: Calculate x- and y-coordinates of the ring

secnorm = (secup - min(secup))./(max(secup)-min(secup)); % normalize sector...

th = 2*pi*secnorm; % ... and then convert to angle between 0 and 2*pi

rmin = 0.8; % inner radius

rmax = 1; % outer radius

xouter = rmax.*cos(th); % coordinates of outer ring (counterclockwise from right)

xinner = rmin.*cos(th);

youter = rmax.*sin(th); % coordinates of inner ring (counterclockwise from right)

yinner = rmin.*sin(th);

% ... to draw the ring, connect the outer circle counterclockwise, then the

% inner circle clockwise, and then back to the first point of the outer

% circle.

x = [xouter; xinner(end:-1:1); xouter(1)]; % ring x coords

y = [youter; yinner(end:-1:1); youter(1)]; % ring y coords

c = [data; data(end:-1:1,:); data(1,:)]; % color data corresponding to each vertex

% Prepare time label (just for reference)

tstr = cellstr(num2str(tmp.Time, '%6.4f')); % # time x 1 cell array

% Step 3: Plot using the color data for the first time step

axes;

p = patch(x,y,c(:,1)); % plot patch

axis equal; % set aspect ratio equal

set(gca, 'visible', 'off', 'clim', [0 1505]); % hide the axis box and ...

% set the color limits to match the data

t = text(0, 1.1, tstr{1}, 'horiz', 'center'); % Add a text label with the time

set(p, 'edgecolor', 'none'); % hide the edges of the patch

colorbar('west'); % add a colorbar

% Step: Loop to animate, changing color data and time label

for it = 2:size(data,2)

pause(0.01);

set(p, 'cdata', c(:,it));

set(t, 'string', tstr{it});

end

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

Start Hunting!
## 4 Comments

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/533218-colour-plot-vs-time-on-a-circle#comment_863208

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/533218-colour-plot-vs-time-on-a-circle#comment_863208

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/533218-colour-plot-vs-time-on-a-circle#comment_864293

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/533218-colour-plot-vs-time-on-a-circle#comment_864293

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/533218-colour-plot-vs-time-on-a-circle#comment_866058

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/533218-colour-plot-vs-time-on-a-circle#comment_866058

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/533218-colour-plot-vs-time-on-a-circle#comment_866218

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/533218-colour-plot-vs-time-on-a-circle#comment_866218

Sign in to comment.