MATLAB: How can i apply for loop

for loopMATLAB

hi i am trying to execute for loop and i am having problem as i have not proficiency in Matlab. In following program when I execute for different values of cfo, i got the value of Fp and simply i can plot the graph by intoducing two new arrays of cfo and Fp. But when i use for loop to plot the graph i get nothing. Kindly tell me what is the problem in this.
h=10;
zo=30;
v=0.4;
vo=1;
for cfo=50e3:25e3:200e3;
ip1 = lognrnd(log(33.3e3),0.605,1,1.2e5);
ip = ip1./1e3;
ymax = 0.5;
y1 = 2;
vmax = zo*ip.*y1*h*(1+((v/vo)*(1/sqrt(2))*1/sqrt(1-(0.5*(v/vo)^2))))
A=find(vmax>1.5*cfo);
n = numel(A)
Fp = 200*(n/120000)*ymax
end
plot (cfo,Fp)
set(gca, 'YScale', 'log')
grid on
hold on

Best Answer

  • I didnot check the code, wheather the correct logic or not. Just show you how you can generate then graph, do array. Keep all constant at the initial part of the code (outside for loop). Now you can modify as per your desired result.
    h=10;
    zo=30;
    v=0.4;
    vo=1;
    cfo=50e3:5e3:200e3;
    for i=1:1:length(cfo)
    ip1=lognrnd(log(33.3e3),0.605,1,1.2e5);
    ip=ip1./1e3;
    ymax=0.5;
    y1=2;
    vmax=zo*ip.*y1*h*(1+((v/vo)*(1/sqrt(2))*1/sqrt(1-(0.5*(v/vo)^2))));
    A=find(vmax>1.5*cfo(i));
    n=numel(A);
    Fp(i)=200*(n/120000)*ymax;
    end
    plot (cfo,Fp)
    set(gca, 'YScale', 'log')
    grid on
    Hope it Helps!
  • Related Question