How to create several subplots without tick labels in a loop?

24 ビュー (過去 30 日間)
Artem Smirnov
Artem Smirnov 2017 年 1 月 16 日
コメント済み: KSSV 2017 年 1 月 16 日
I have got the following problem. I have several subplots within one figure, that are created in a loop. I want to get rid of the X axis labels on all of them, except for the last subplot in a loop. How can I do that? Here is what I tried.
for i=1:1:10
figure(1);
s(i)=subplot(10,1,i)
t=1:1440;
y=sin(t); %for instance
plot(t,y);
ax=gca;
if s(i)~=s(10)
set(ax,'XTick', []);
else
ax.XAxis.TickValues =0:60:1440;
ax.XAxis.MinorTick='on';
ax.XAxis.MinorTickValues=0:60:1440;
grid on;
ax.XMinorGrid='on';
end
end
This, actually, does not work. All the X labels are still there. Could you please help me to do that?

採用された回答

KSSV
KSSV 2017 年 1 月 16 日
clc; clear all ;
for i=1:1:10
figure(1);
s(i)=subplot(10,1,i)
t=1:1440;
y=sin(t); %for instance
plot(t,y);
ax=gca;
if i == 10
axis on
else
axis off
end
% if s(i)~=s(10)
% set(ax,'XTick', []);
% else
% ax.XAxis.TickValues =0:60:1440;
% ax.XAxis.MinorTick='on';
% ax.XAxis.MinorTickValues=0:60:1440;
% grid on;
% ax.XMinorGrid='on';
% end
end
  3 件のコメント
Artem Smirnov
Artem Smirnov 2017 年 1 月 16 日
編集済み: Artem Smirnov 2017 年 1 月 16 日
I found the way to do that!))
for i=1:1:10
figure(1);
s(i)=subplot(10,1,i)
t=1:1440;
y=sin(t); %for instance
plot(t,y);
ax=gca;
if i == 10
axis on
else
set(gca,'xticklabel',{[]})
end
end
KSSV
KSSV 2017 年 1 月 16 日
clc; clear all ;
for i=1:1:10
figure(1);
s(i)=subplot(10,1,i) ;
t=1:1440;
y=sin(t); %for instance
plot(t,y);
ax=gca;
if i ~= 10
set(gca,'xtick',[])
set(gca,'xticklabel',[])
end
% if s(i)~=s(10)
% set(ax,'XTick', []);
% else
% ax.XAxis.TickValues =0:60:1440;
% ax.XAxis.MinorTick='on';
% ax.XAxis.MinorTickValues=0:60:1440;
% grid on;
% ax.XMinorGrid='on';
% end
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by