Writing titles and x/y labels inside a for loop and if-statements

18 次查看(过去 30 天)
I am ploting four different subplots and i am trying to title and label each axis of each subplot. The only one that gets titled and labled is the very last subplot. How might i fix this issue? See code and pictures.
F0 = 32100:125:32475;
for i = 1:1:4
FS = 8000;
f0=F0(i)/FS;
x = sin(2*pi*f0.*n + phi);
stem(n, x)
if (i == 1)
subplot(2,2,i)
stem(n, x)
title('Hz');
ylabel('[x(n)]');
xlabel('n');
elseif (i == 2)
subplot(2,2,i)
stem(n, x)
title('225Hz');
ylabel('[x(n)]');
xlabel('n');
elseif (i == 3)
subplot(2,2,i)
stem(n, x)
title('350Hz');
ylabel('[x(n)]');
xlabel('n');
elseif (i == 4)
subplot(2,2,i)
stem(n, x)
title('475Hz');
ylabel('[x(n)]');
xlabel('n');
end
end

采纳的回答

G A
G A 2021-4-17
remove
stem(n, x)
before if statement

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Object Properties 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by