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!