matlab - Animation in R without saving figures and without external software -
is possible create animation in r directly, in matlab, without saving figures , using external software? executing script?
consider following example in matlab.
t = (1:360) / 180 * pi; % 360 angles in radians 1 360 degrees n = length(t); % length of vector x = cos(t); % cosines y = sin(t); % sines f = figure; % create figure , handle hh = plot(2, 2, 'or', 'markerfacecolor', 'r', 'markersize', 10); % create plot , handle set(gca, 'xlim', [-1 1]); % set x axis limits set(gca, 'ylim', [-1 1]); % set y axis limits axis square; axis off; % set more properties axes while ishandle(f) % until user closes figure try % try loop, if encouter error break loop ii = 1:n % angles set(hh, 'xdata', x(ii)) % change point x coordinate set(hh, 'ydata', y(ii)) % change point y coordinate pause(0.01) % make little pause end end end
after hrbrmstr's answer, have tried this:
t <- (1:360) / 180 * pi n <- length(t) x <- cos(t) y <- sin(t) while(true) { (i in 1:n) { plot(x[i], y[i], ann=false, pch=20, axes=false, xlim=c(-1, 1), ylim=c(-1, 1), col="red", cex=4, asp=1) sys.sleep(0.01) } }
and seems doing job. thanks!
i have tried this:
t <- (1:360) / 180 * pi n <- length(t) x <- cos(t) y <- sin(t) while(true) { (i in 1:n) { plot.new() usr<-par("usr") par(usr=c(-1.1, 1.1, -1.1, 1.1)) lines(x, y, col="green") points(x[i], y[i], pch=20, col="red", cex=4, asp=1) sys.sleep(0.01) } }
which closer had in mind. find r's "paper , pen" drawing model terrible. isn't there way around that?
i'm not try figure out matlab plotting doing w/r/t aesthetics.
this:
while(true) { barplot(sample(1:1000, 10)) sys.sleep(0.5) }
"animates" random bar chart display pretty imo and:
t <- (1:360) / 180 * pi n <- length(t) x <- cos(t) y <- sin(t) (i in 1:n) { plot(x[1:i], y[1:i], type="p") sys.sleep(0.15) }
does 1 basic bit of "animation" of points in 1 fashion and:
for (i in 1:n) { plot.new() points(x[1:i], y[1:i]) sys.sleep(0.15) }
in (though 1 needs work setting x & y limits avoid graphics device errors).
all 3 stop when asked "stop" gui or when for
loop done.
not "disproportionately complex". more "not familiar matlab person".
Comments
Post a Comment