MATLAB: Single “x-axis graph axis numbers code” to work multi plots

MATLABplotsubplot

In the code below, is it possible to implement changing the x-axis numbers to display in significant figures instead of the exponent form:
curtick = get(gca, 'XTick');
set(gca, 'XTickLabel', cellstr(num2str(curtick(:))));
by using this code once for the multi subplots instead of putting to code in each subplots?
% Frequency vector
x = 10:1000;
% Phase noise vector
y = 10:1000;
% Graph settings
subplot(2, 2, 1);
semilogx(x,y); grid on;
title('Pass1 Response');
xlabel('Frequency (Hz)'); ylabel('Amplitude');
subplot(2, 2, 2);
semilogx(x,y); grid on;
title('Data after Pass1');
xlabel('Frequency (Hz)'); ylabel('Amplitude');
subplot(2, 2, 3);
semilogx(x,y); grid on;
title('Pass 2 Response');
xlabel('Frequency (Hz)'); ylabel('Amplitude');
subplot(2,2,4);
semilogx(x,y); grid on;
title('Data after Pass 2');
xlabel('Offset Frequency (Hz)'); ylabel('Amplitude');
Or is there a simpler method to have all the x-axis display in significant numbers for the subplots instead of using the above code for each subplot?

Best Answer

If you save the handles of your subplots, you can apply the function to all axes, either in a loop or via arrayfun afterwards:
% Frequency vector
x = 10:1000;
% Phase noise vector
y = 10:1000;
% Graph settings
ttl = {'Pass1 Response', ...
'Data after Pass1', ...
'Pass 2 Response', ...
'Data after Pass 2'};
for ii = 1:4
ax(ii) = subplot(2,2,ii);
semilogx(x,y);
grid on;
title(ttl{ii});
ax(ii).XTickLabel = strtrim(cellstr(num2str(ax(ii).XTick')));
end