필터 지우기
필터 지우기

How to use subplot in a loop?

조회 수: 4 (최근 30일)
kc
kc 2022년 3월 2일
댓글: kc 2022년 3월 2일
Hello there this is the code snippet. I want to use subplot for say 3 X 3 grid. But I am not able to give correct position.
t=0:.001:5;
% for a period of 1sec 10 cycles and duty cycle of 20
f=input('Enter Frequrncies: ');%[5 10 15];
d_t=input('Enter Duty cycles: ');%[20, 50,80];
for i=1:length(f)
for j=1:length(d_t)
sq=square(2*pi*f(i)*t,d_t(j));
subplot(length(f),length(d_t),i*j)
plot(t,sq)
title(sprintf('%dHz square function for a duty cycle of %d',f(i),d_t(j)))
xlabel('Time')
ylabel('Amplitude')
grid on
end
end
Here it over writes the old plot, by multiplying (i*j) in subplot.

채택된 답변

KSSV
KSSV 2022년 3월 2일
for i = 1:9
subplot(3,3,i)
end
  댓글 수: 3
KSSV
KSSV 2022년 3월 2일
count = 0 ;
m = length(f) ;
n = length(d_t) ;
for i = 1:m
for j = 1:n
count = count+1;
subplot(3,3,count)
end
end
kc
kc 2022년 3월 2일
thank you :)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by