Animating imagesc plots

I'm trying to animate an imagesc plot using refreshdata, but with these plots, there is no 'CDataSource' property with which I can link the data I would like to change and the new values. Is there a way to link data sources in imagesc plots? I know that there is a 'CData' property but this doesn't seem to work (at least in the way I've tried).
I currently have an array, plot it using imagesc, and under the hold condition, include a for loop which includes the varying data as well as the refreshdata, pause and drawnow commands.
This is just meant to be a simple animation displaying a simple concept, so as long as I can just update this data that is fine. Any other method ideas for animating arrays would be greatly appreciated.
*Note: I have used the refreshdata method for animating plots in the past, only it was using the plot command (not imagesc) and I was using 2 data sources.

2 Kommentare

Jan
Jan am 10 Jun. 2011
What are "the varying data"? It would be helpful if you post the code, such that we can add the changes and do not have to create the whole code from scratch.
James
James am 10 Jun. 2011
My apologies, wasn't thinking. Here's what I have so far. It's the beginnings of an animation showing the amplitude and phase behavior in cavity ring-down spectroscopy, so please excuse the odd array.
function Cavity( f,phi,reps )
%Cavity - written by James Mester
% This function shows the intensity modulation of the incident beam,
% cavity resonance and transmitted beam in cavity ring-down spectroscopy.
% VARIABLES:
% f - frequency (Hz)
% phi - phase difference (degrees)
% reps - repetitions (periods of f)
% define angular frequency
w = 2 * pi * f;
%define phase in radians
phir = phi * pi / 180;
%define period
T = 1 / f;
%define time vector
t = 0:.001:(reps*T);
%build cavity array
cavity = zeros(1001,1001);
cavity(:,:) = 1;
coeff = 100 / (500^2);
for x = -500:500
y(x+501) = coeff*x^2;
end
for i=1:25
for x=1:1001
cavity(x,200+i+floor(y(x)))=0;
cavity(x,800-i-ceil(y(x)))=0;
end
end
for x = 251:750
cavity(x,(225+ceil(y(x))):(775-ceil(y(x)))) = 0.2;
end
for x = 351:650
cavity(x,1:(201+floor(y(x)))) = 0.4;
end
for x = 401:600
cavity(x,(800-ceil(y(x))):1001) = 0.6;
end
%plot figure
figure(1);
% hold on
fig = imagesc(cavity);
colormap(bone)
set(fig,'CData',cavity)
% linkdata on
%for loop that varies intensity values
for i = 1:length(t)
for x = 351:650
cavity(x,1:(201+floor(y(x)))) = -0.3*cos(w*t(i))+0.7;
end
for x = 251:750
cavity(x,(225+ceil(y(x))):(775-ceil(y(x)))) = -0.4*cos(w*t(i)-phir)+0.6;
end
for x = 401:600
cavity(x,(800-ceil(y(x))):1001) = -0.2*cos(w*t(i)-phir)+0.8;
end
pause(0.01)
refreshdata(fig,'caller')
drawnow
end
% hold off
end

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jan
Jan am 10 Jun. 2011

1 Stimme

I suggest to ask Google for "animate Matlab CData".

Kategorien

Gefragt:

am 10 Jun. 2011

Community Treasure Hunt

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

Start Hunting!

Translated by