필터 지우기
필터 지우기

matlab hanging for the below code

조회 수: 1 (최근 30일)
Shashidhar Kudari
Shashidhar Kudari 2019년 12월 3일
댓글: Walter Roberson 2019년 12월 4일
Fs=10
t=0:1/Fs:1
x1=cos(2*pi*t*3)+cos(2*pi*t*4)+cos(2*pi*t*8)+cos(2*pi*t*10)
fft_x1=fft(x1)
fft_shift=fftshift(fft_x1)
mag=abs(fft_shift)
N=length(t)
f=-Fs/2:Fs/N:Fs/2-(Fs/N)
stem(f,mag)
fr=[]
for k=1:N
sum=0
for n=1:N
out=x1(n)*exp((-i*pi*2*n*k)/N)
sum=sum+out
end
fr=[fr sum]
end
fr=fftshift(fr)
mag1=abs(fr)
plot(t,x1)
title('signal time')
stem(f,mag1)
for this code matlab is hanging ,but for other programs matlab is working fine what is the problem in the code

채택된 답변

Image Analyst
Image Analyst 2019년 12월 3일
It doesn't hang for me.
But you should not use the name "sum" for your variable since it's the name of a very important built-in function that you will overwrite.
  댓글 수: 4
Shashidhar Kudari
Shashidhar Kudari 2019년 12월 4일
if we overwrite the inbuilt function ,then how should we correct that?
whether it gets corrected on restart of matlab?
Walter Roberson
Walter Roberson 2019년 12월 4일
You can clear followed by the name of the function.
Exception: if what you overwrote was clear itself, then
builtin('clear', 'clear')
If you ovewrote builtin and clear then you need the special behaviour
builtin clear clear
This will, as a special case, not invoke
builtin('clear', 'clear')
where builtin in the above line refers to whatever you overwrote builtin with.

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

추가 답변 (1개)

Raj
Raj 2019년 12월 3일
Doesn't seem to be hanging for me!
Capture.JPG
Where are you having problem? Have you tried running in Debug mode?
  댓글 수: 1
Walter Roberson
Walter Roberson 2019년 12월 3일
It does not hang for me either.

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

카테고리

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

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by