If you are doing 2nd approximation and IRF analysis, the following matlab could help you solve your problem.
yy is the IRF for all endogenous variables. The following are the way Dynare doing IRF calculation.
by default, replic = 50 ; long =40; drop =100; Chol_S are the standard deviation of all shocks, diagnoal.
yy=0;
for j=1:replic %draw two shocks
ex1(:,i_exo_var)=randn(long+drop,nxs)*chol_S;
ex2 = ex1;
%add one standard deviation of two shocks to exogenous shock path, assuming totally 4 shocks
ex2(drop+1,:)=ex2(drop+1,:)+[0.01 0.01 0 0];
y1=simult_(temps,oo_.dr,ex1,iorder); % using dynare built-in function to simulate the whole model
y2=simult_(temps,oo_.dr,ex2,iorder);
yy=yy+(y2(:,M_.maximum_lag+drop+1:end)-y1(:,M_.maximum_lag+drop+1:end));
end
yy=yy/replic;
if output is the 1st varaibles in declaration order, the yy(1,:) is the IRF of output respond to two shocks.