matlab hanging for the below code
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Shashidhar Kudari
le 3 Déc 2019
Commenté : Walter Roberson
le 4 Déc 2019
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
0 commentaires
Réponse acceptée
Image Analyst
le 3 Déc 2019
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 commentaires
Walter Roberson
le 4 Déc 2019
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.
Plus de réponses (1)
Raj
le 3 Déc 2019
Doesn't seem to be hanging for me!
Where are you having problem? Have you tried running in Debug mode?
1 commentaire
Voir également
Catégories
En savoir plus sur Desktop dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!