Matlab plot recording to a video

77 views (last 30 days)
MaD
MaD on 10 Sep 2019
Answered: darova on 10 Sep 2019
hi,
I woulkd like to create a video where a plot is created based on the .txt file read. The plot should have the 'main screen' and a 'zoomed screen' in the conner and the variable should be recorded simultaneously in both plots.
Im sharing my current example.
Is it possible to specify the target plot for the variable? or any other suggestion?
%% Create figure frame
fid = figure;
hold on
grid on
xlim([-0.1 1.12]) %setting hard limits for x-axis
ylim([0.8 1.2]) %setting hard limits for y-axis
h=axes('Parent', fid, 'position',[0.5 0.2 0.3 0.3]);
%% Set up and writing the movie.
writerObj = VideoWriter('out_movie_540_.avi'); % movie name.
writerObj.FrameRate = 540/4; % Frames per second. Larger number correlates to smaller movie time duration.
open(writerObj);
for i=1:size(tnow)
% pause(0.1); % The command designed to slow down the live recording of the matlab graph.
figure(fid); % Makes sure you use your desired frame.
plot(tnow(i),p_pf1(i),'r.');
if mod(i,4)==0 % Uncomment to take 1 out of every 4 frames.
frame = getframe(gcf); % 'gcf' can handle if you zoom in to take a movie.
writeVideo(writerObj, frame);
end
end
hold off
close(writerObj);% Saves the movie.

Answers (1)

darova
darova on 10 Sep 2019
Example
clc,clear
x = linspace(0,10);
y = sin(x) + 0.1*cos(10*x);
fid = figure;
h1 = gca;
plot(x,y);
hold on
h2 = axes('Parent',fid,'Position',[0.6 0.2 0.2 0.2]);
plot(x,y)
hold on
for i = 1:length(x)
h(1) = plot(h1,x(i),y(i),'or');
h(2) = plot(h2,x(i),y(i),'or');
xlim(h2, [-1 1]+x(i))
ylim(h2, [-1 1]+y(i))
pause(0.2)
delete(h)
end
hold off
But when i try to plot in the same figure
fid = figure(1)
export_fig_out.png
Any idea?

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!