How to fix the Frame size error when creating a video.?
이전 댓글 표시
Hello
Requesting help to fix the error encountered during the video creation.
Trying to generate a video by varying one parameter. Facing with the following error:
Error using VideoWriter/writeVideo (line 368)
Frame must be 977 by 771
Error in Movie (line 115)
writeVideo(vidObj,currFrame);
I did review the solution to a similar problem. But I couldnt use it to fix the mesh plot that I am generating. Below is my code:
%% Plotting the curve to be reflected
clear all
close all
clc
% Constants
I0 = 1; % Initial X-ray beam intensity
rCu = 900; % radius of copper wire, um
rPMMA = 400; % radius of the PMMA, um
lamda = 7.1255e-5; % x-ray wavelength, um, (17400 eV)
k = 2*pi/lamda; % wavenumber, um^-1
beta_Cu = 2.5914E-07; % https://henke.lbl.gov/optical_constants/
beta_PMMA = 5.0314E-10; % https://henke.lbl.gov/optical_constants/
mu_Cu = beta_Cu*2*k; % Absorption coefficient, mu=2*beta*k, um^-1
mu_PMMA = beta_PMMA*2*k; % Absorption coefficient, mu=2*beta*k, um^-1
%% Guass
xstart=-2;
xstop=2;
xpoints=200;
xinc=(xstop-xstart)/(xpoints-1);
ystart=-2;
ystop=2;
ypoints=200;
yinc=(xstop-xstart)/(xpoints-1);
for ii=1:xpoints
x(ii)=xstart+xinc*(ii-1);
for jj=1:ypoints
y(jj)=ystart+yinc*(jj-1);
z=x(ii)*x(ii)+y(jj)*y(jj);
Is(ii,jj)=exp(-z);
end
end
%% Computing intensity versus x-position
%I(x)= I0*exp(−(µCu*LCu(x)+µPMMA*LPMMA(x))]
%Assume wire long axis is along z-axis, with center at x=0.
%Assume x-rays travel in y direction.
rT=rCu+rPMMA; % Total radius of the copper wire ,um
x=(-2:.02:1.98)*rT; %x values (um) (range = +-2*rT)
t_Cu=2*sqrt(max(rCu^2-x.^2,0));
t_total=2*sqrt(max(rT^2-x.^2,0));
t_PMMA=t_total-t_Cu;
% mu_PMMA steps
% steps = (1:10:100);
steps =[1 10 20 30 40 50]
mu_PMMA_inc = (beta_PMMA*2*k)*steps;
for i=1:length(mu_PMMA_inc)
It(i,:)=exp(-mu_Cu*t_Cu-mu_PMMA_inc(i)*t_PMMA);
end
%% Movie
% Opening a figure and create the axes
figure
% Create and open the video object
nframes=6;
Frames=moviein(nframes);
vidObj = VideoWriter('Cu_wire_Xray.avi');
vidObj.FrameRate = 1; % frames per second.
open(vidObj);
% Looping over the data to create the video
ax = gca();
for j=1:nframes
Id = It(j,:).*Is; %Detector intensity
% Plot the data
h=mesh(Id);
xlabel('$x$ (mm)','interpreter','latex')
ylabel('$y$ (mm)','interpreter','latex')
zlabel('$I$','interpreter','latex')
title(['Absorptoion coefficient, mu_PMMA =',num2str(mu_PMMA_inc(j))])
% pause(0.1);
% STEP 2
% Getting the current frame
currFrame = getframe(gca);
size(currFrame.cdata);
% STEP 3
%
% Write the current frame
writeVideo(vidObj,currFrame);
%
delete(h)
end
% Closing (and save) the video object
close(vidObj);
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Audio and Video Data에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!