matlab - Animated Discrete Stem Plot -
so want create animated plot of discrete-time complex exponential function. simplest non-animated plot given this:
n=-5:40; x=(exp((3*4j)*n)).*(n>=0); y=real(x); subplot(2,1,1); stem (n,y) z=imag(x); subplot(2,1,2); stem (n,z)
how animate show function different numbers of samples considered in given interval (assuming have time interval specified start second , end second , vector containing number of sample values in given interval)?
i tried along these lines:
figure,hold on xlim([min(x(:)) max(x(:))]) ylim([min(y(:)) max(y(:))]) %// plot point point k = 1:numel(x) stem (k,y) %// choose own marker here pause(0.001); end
that doesn't compile. how achieve this?
short answer:
make following 2 changes:
① replace xlim([min(x(:)) max(x(:))])
xlim([1 numel(x)])
.
② replace stem (k,y)
this: stem (k,y(k))
.
detailed answer:
① xlim([min(x(:)) max(x(:))])
giving following error:
error using matlab.graphics.axis.axes/set while setting 'xlim' property of 'axes': not valid limitswithinfs value. complex inputs not supported
the error message tells problem is. vector x
contains complex numbers. time axis having complex numbers doesn't imply anything.
it seems want replace line xlim([min(x(:)) max(x(:))])
this: xlim([1 numel(x)])
.
② inside loop, stem (k,y)
giving error:
error using stem (line 46) x must same length y.
the error message tells problem is. here k
scalar (1x1) y
1x46 vector.
since want plot y
point point, replace stem (k,y)
this: stem (k,y(k))
.
output after making mentioned fixes:
Comments
Post a Comment