필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
monkey_matlab
monkey_matlab 2015년 9월 17일
댓글: Kelly Kearney 2015년 9월 17일
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?

채택된 답변

Kelly Kearney
Kelly Kearney 2015년 9월 17일
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
monkey_matlab
monkey_matlab 2015년 9월 17일
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 2015년 9월 17일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by