MATLAB: How to simply this script to create figures

figureMATLAB

I prepared the following script to create two figures. Each figure has 2-by-6 subplots. The only difference between them is that the first one uses a plot function and the second one uses a semilogy function. Otherwise, legend, xlabel, ylabel, and position are the same. Also, I want to export the figures as Fig1.eps and Fig2.eps files. How can I further simply this script to avoid repeated codes?
harray(1)=figure('Name',fname{1});
for k1 = 1:12
h{k1} = subplot(2,6,k1)
hLine{k1} = plot(X,Y(k1,:),X,Z(k1,:));title(type{k1});
end
legend('test1','test2');
xlabel(h{7},'\fontname{Helvetica}X');
xlabel(h{8},'\fontname{Helvetica}X');
xlabel(h{9},'\fontname{Helvetica}X');
xlabel(h{10},'\fontname{Helvetica}X');
xlabel(h{11},'\fontname{Helvetica}X');
xlabel(h{12},'\fontname{Helvetica}X');
ylabel(h{1},'\fontname{Helvetica}Y');
ylabel(h{7},'\fontname{Helvetica}Y');
set(harray(1), 'Position', [0 0 1366 768]);
print -depsc Fig1
harray(2)=figure('Name',fname{2});
for k1 = 1:12
h{k1} = subplot(2,6,k1)
hLine{k1} = semilogy(X,Y(k1,:),X,Z(k1,:));title(type{k1});
end
legend('test1','test2');
xlabel(h{7},'\fontname{Helvetica}X');
xlabel(h{8},'\fontname{Helvetica}X');
xlabel(h{9},'\fontname{Helvetica}X');
xlabel(h{10},'\fontname{Helvetica}X');
xlabel(h{11},'\fontname{Helvetica}X');
xlabel(h{12},'\fontname{Helvetica}X');
ylabel(h{1},'\fontname{Helvetica}Y');
ylabel(h{7},'\fontname{Helvetica}Y');
set(harray(2), 'Position', [0 0 1366 768]);
print -depsc Fig2

Best Answer

Delete the second half of the code. After you print the first figure, do
cellfun(@(axes_handle) set(axes_handle, 'YScale', 'log'), h);
Then you can print figure 1 again.
That is, the difference between regular plot and semilogy is that in semilogy plot, the YScale property is set to 'log'. The cellfun is there because you happened to use cells to store the axes handles; you could have used a plain arrays instead for your h and hLine .