hello sir i want real values but when i write my function in matlab s(ii)==real (s(ii)); it give me complex value how to solve it

1 vue (au cours des 30 derniers jours)
ii=1:2;
s(ii)=real(s(ii));
s(ii)=round(log(z(ii))*N/j/2/pi)+1;
this is my short function please guide me where i am wrong

Réponse acceptée

Thorsten
Thorsten le 30 Juin 2016
Modifié(e) : Thorsten le 30 Juin 2016
real is the real part of a complex number. Unless you do not have re-defined Matlab's real, this should work.
To check if you use the real "real", type
which real
Further, the lines
s(ii)=real(s(ii));
s(ii)=round(log(z(ii))*N/j/2/pi)+1;
don't make sense. The result would be the same without the first line, because s ist not used in the second line, so the s from the first line is simple replaced.
Do you want
z(ii)=real(z(ii));
s(ii)=round(log(z(ii))*N/j/2/pi)+1;
Also, if the argument of log is negative, the result will be complex. And round rounds, but does not discard the imaginary part. You can use abs or real, but of course I don't know if this is what you want to compute.
  2 commentaires
Walter Roberson
Walter Roberson le 30 Juin 2016
Perhaps you want to reverse the lines,
s(ii)=round(log(z(ii))*N/j/2/pi)+1;
s(ii)=real(s(ii));
irfan
irfan le 30 Juin 2016
Modifié(e) : irfan le 30 Juin 2016
sir thank you i understand your point

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by