Helping with the plot of a function

Hello!! I am trying to plot a function in freq-domain that decrease with f, I should get a kind of sin that decrease when time goes by, but I am not getting it. This is the code Tc=1*10^-3;
f=linspace(0,10000000);
R=zeros(size(f));
for a=1:1:100
R(f)=i*Tc*sinc(a(f)*Tc/2)*sin(pi*a(f)*Tc/2);
end
plot(f,R(f))
Please, someone could help.
Thanks in advance, Nicolas

Risposte (1)

Jan
Jan il 13 Mar 2012

0 voti

  • Is the multiplication by i intented?
  • What is Tc?
  • a is the scalar loop counter, therefore a(f) should fail.
  • You assign R(f) in the loop, but this does not depend on the loop counter a.

3 Commenti

Hello Jam!
i is the imaginatary unit and I want to multiply by it, then Tc is just a period that I defined before. I saw what you mean and now I modified my code but, now I can get the plot buut nothing is on it
Tc=1*10^-3;
f=linspace(0.1,2e6);
for aux=1:1:100;
R(aux)=i*Tc*sinc(f(aux).*Tc/2)*sin(pi*f(aux).*Tc/2);
end
plot(f,R(aux))
thanks, I dont know where is the problem
In fact, when I check in the workspace it appear that aux is a single value = 100, not a vector....
Jan
Jan il 13 Mar 2012
Yes, aux is a scalar. This is the expected and wanted behaviour of a FOR-loop. Try this:
for i = 1:10; disp(i); x(i) = i*i; end, disp(x)
For your problem: "plot(f, R)" will use all elements of R.

Accedi per commentare.

Categorie

Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange

Richiesto:

il 13 Mar 2012

Community Treasure Hunt

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

Start Hunting!

Translated by