I made this code shorter
clear; close all;clc
load('data_1.mat')
pathV = [folder,'\export_video'];
%% Create figures
hfig_IR = figure('PaperUnits','centimeters','PaperSize',[im.width im.height],...
'PaperPosition',[0 0 im.width im.height],'Units','centimeters',...
'Position',[2 15 im.width im.height],'NumberTitle','off',...
'name','Innenring','NextPlot','replacechildren',...
'color', [1 1 1],'menubar','none');
hfig_AR = figure('PaperUnits','centimeters','PaperSize',[im.width im.height],...
'PaperPosition',[0 0 im.width im.height],'Units','centimeters',...
'Position',[2 2 im.width im.height],'NumberTitle','off',...
'name','Aussenring','NextPlot','replacechildren',...
'color', [1 1 1],'menubar','none');
% Set outer bounds
set(hfig_IR, 'OuterPosition',[2 15 im.width im.height])
set(hfig_AR, 'OuterPosition',[2 2 im.width im.height])
% Create axes
hax_AR = axes('Fontname',font.name,'parent',hfig_AR,...
'Units', 'normalized', 'OuterPosition', [.01 .01 .99 .99],...
'NextPlot','replacechildren','Box','on');
hax_IR = axes('Fontname',font.name,'parent',hfig_IR,...
'Units', 'normalized', 'OuterPosition', [.01 .01 .99 .99],...
'NextPlot','replacechildren','Box','on');
%% p_c - Kontaktdrück
if bilder.p_c
CBarTickIR = linspace(pc_lim_IR(1),pc_lim_IR(2),TeilungCB);
CBarTickAR = linspace(pc_lim_AR(1),pc_lim_AR(2),TeilungCB);
cla(hax_IR);cla(hax_AR)
parfor k = start:endstep
MakePic_pc('p_c',1,xData_IR,yData_IR,p_c_IR,pc_lim_IR,CBarTickIR,X_IR_limits,Y_IR_limits,LS_IR,SS_IR,k,font,folder,im,hfig_IR,hax_IR)
MakePic_pc('p_c',2,xData_AR,yData_AR,p_c_AR,pc_lim_AR,CBarTickAR,X_AR_limits,Y_AR_limits,LS_AR,SS_AR,k,font,folder,im,hfig_AR,hax_AR)
end
if MakeVideo
appendix='\p_c';
pathB = [folder im.folder appendix];
create_video(pathB,pathV,appendix,'AR');
create_video(pathB,pathV,appendix,'IR');
end
end
function MakePic_pc(Valuename,flagR,xData,yData,value,value_lim,CBarTick,X_limits,Y_limits,LS,SS,k,font,folder,im,hfig,hax)
if flagR == 1
Ring = 'Innenring';
ring = 'IR';
elseif flagR == 2
Ring = 'Aussenring';
ring = 'AR';
end
fprintf('[%s %s] LS_%s SS_%s\n',Valuename,Ring,LS{k},SS{k});
figure(hfig);
contourf(xData(:,:,k),yData(:,:,k),value(:,:,k),im.cmapclass,'EdgeColor','none','Parent',hax);
colormap(jet);
caxis(value_lim);
haxes_cb=colorbar(hax,'Ylim',value_lim,'Location','northoutside');
haxes_cb.Label.String = 'Kontaktpressung p_c [MPa]';
haxes_cb.Label.FontName = font.name;
haxes_cb.Label.FontSize = font.size;
set(haxes_cb,'Ytick',CBarTick,'YTickLabel',round(CBarTick));
set(hax,'XLim',X_limits,'YLim',roundn(Y_limits,-2));
hax.XTick = roundn(linspace(X_limits(1),X_limits(2),6),-1);
hax.YTick = roundn([linspace(Y_limits(1),0,3) linspace(Y_limits(2)/2,Y_limits(2),2)],-2);
text(0.99,0.01,sprintf('p_{c,max}=%dMPa',round(max(value,[],'all'))),'Units','normalized',...
'Fontname',font.name,'Fontsize',font.size-1,'HorizontalAlignment','right',...
'VerticalAlignment','bottom','BackgroundColor','w','Margin',0.01,'Parent',hax)
set(hax,'color', [1 1 1],'Fontname',font.name,'Fontsize',font.size,...
'PlotBoxAspectRatio',[1 1 1],'DataAspectRatio',[1 1 1]);
im_folderB=sprintf('%s/%s',im.folder,Valuename);
if(~isfolder(strcat(folder,im_folderB)))
mkdir(strcat(folder,im_folderB));
end
exportgraphics(hfig,sprintf('%s/%s/%s__%03i_%s__LS%s_SS%s.png',folder,im_folderB,ring,k,Valuename,LS{k},SS{k}),'Resolution',im.res)
end
function create_video(pathB,pathV,appendix,ring)
if(~isfolder([pathV,appendix]))
mkdir([pathV,appendix]);
end
images = dir(fullfile(pathB,[ring,'*.png']));
video = VideoWriter(fullfile(pathV,appendix,[appendix,'_',ring]),'Motion JPEG AVI');
video.Quality = 100;
video.FrameRate = 5;
open(video);
for ii=1:length(images)
I = imread(fullfile(pathB,images(ii).name));
writeVideo(video,I);
end
close(video);
end
Error using VideoWriter/writeVideo (line 368)
Frame must be 1829 by 1125
Error in code>create_video (line 103)
writeVideo(video,I);
Error in code (line 44)
create_video(pathB,pathV,appendix,'IR');