single "x-axis graph axis numbers code" to work multi plots

1 visualización (últimos 30 días)
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?

Respuesta aceptada

Kelly Kearney
Kelly Kearney el 17 de Sept. de 2015
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
  2 comentarios
monkey_matlab
monkey_matlab el 17 de Sept. de 2015
Thanks for your response, however, I guess that I oversimplified my plots. The y data is different for each plot. So for Pass 1 it would actually be `semilogx(x, y1)`, for data after Pass1 ,it would be `semilogx(x, y2)`...and so on. If this is the case, do I also put an index to the y, like y{ii}?
Kelly Kearney
Kelly Kearney el 17 de Sept. de 2015
Yes, if you're going to apply the same analysis/plotting/etc. to several datasets, I'd recommend storing them in arrays that can be easily referenced by index. In this example, either a 991 x 4 array (so you can reference y(:,1), y(:,2), ...) or a 1 x 4 cell array of vectors ( y{1}, y{2}, ...).
A little data storage planning ahead of time can make your code a lot easier to read, maintain, and change down the road.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by