single "x-axis graph axis numbers code" to work multi plots
조회 수: 1 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
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
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 Center 및 File Exchange에서 Subplots에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!