plot a graph using For statement
Afficher commentaires plus anciens
Hi, I wonder if anyone can help.
I want to plot a function called mag(m2,1) from x-axis 10 to 500 but i want to simplify the code so that i dont have to rewrite cases where m and n are other numbers, say m=3,n=4 ; m=1,5 etc, generally for m=1 to 5 and n=1 to 5, for codes below, i only put 2 cases where m=1 n=1 and m=1 n=2. At the end i want to add all the plot of m=1..5, n=1..5.
for num2 = 10:500
f=1e-10+(num2-1);
Freq(num2,1)=f;
coef_HFv=a;
for m=1
for n=1
HHFv1=HHFv1+sin(m*n);
end
end
HFv1(num2)=coef_HFv*HHFv1;
for m=1
for n=2
HHFv2=HHFv2+sin(m*n);
end
end
HFv2(num2)=coef_HFv*HHFv2;
end
mag=zeros(491,1);
for m2=10:500
mag(m2,1)=log10(HFv1(m2))+log10(HFv2(m2));
end
figure(1)
plot(Freq(10:500,1), mag(10:500,1), 'LineWidth',2);
grid on
3 commentaires
Youssef Khmou
le 13 Fév 2013
Define all the variables you have to test the code, a, HHFv1 , etc,
Eric Truslow
le 13 Fév 2013
Actually, your code should not work since you have not initialized HHFv1 to a value:
HHFv1=HHFv1+sin(m*n)
Is this sum important?
Youssef Khmou
le 13 Fév 2013
where is the variable a, and as you want m and n from 1to 5 then HHFv1 and HHFv2 are the same and are equal .
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!