please why i cant get a figure ( it give me an empty figure)
Show older comments
L=16;
for n=1:100:500
Pidle=(1-(1/L))^n;
Psucc = (n*(1-1/L)^(n-1)) ;
Pcoll=(1-Pidle0-Psucc0);
c= L*(1-1/L)^n;
end
plot(n,c);
Answers (2)
Walter Roberson
on 3 Jun 2015
When you have a "for" loop, such as
for n = 1 : 100 : 500
then after the "for" loop, the controlling variable ("n") is left at the value that it had in the last iteration of the loop. In your code that means that at the end of the loop, "n" will be 500.
When you have an unindex assignment in a "for" loop, such as
for n = 1 : 100 : 500
c = L*(1-1/L)^n;
end
then that variable will get overwritten completely on every iteration of the "for" loop. At the end of the "for" loop, the variable will have only the value that it had on the last iteration.
So at the end of your "for" loop, n will be a scalar, and c will be a scalar, and you are plotting with just that one point. The plot is not empty, but it only has one point to draw.
4 Comments
safi marwa
on 3 Jun 2015
Ilham Hardy
on 3 Jun 2015
Have you looked into the first example?
s = 10;
H = zeros(s);
for c = 1:s
for r = 1:s
H(r,c) = 1/(r+c-1);
end
end
Pay attention to H(r,c) = .. part of the code.
safi marwa
on 3 Jun 2015
Walter Roberson
on 3 Jun 2015
nvals = 1:100:500;
numn = length(nvals);
c = zeros(numn, 1);
for K = 1 : numn
n = nvals(K);
Pidle=(1-(1/L))^n;
Psucc = (n*(1-1/L)^(n-1)) ;
Pcoll=(1-Pidle0-Psucc0);
c(K) = L*(1-1/L)^n;
end
plot(nvals, c);
L=16;
N = 1:100:500;
Pidle = (1-(1/L)).^N;
Psucc = N.*(1-1/L).^(N-1);
Pcoll = 1-Pidle-Psucc;
C = L*(1-1/L).^N;
plot(N,C)
which produces this plot:

Although note that your code calculates Pcoll, these values are never used.
1 Comment
safi marwa
on 3 Jun 2015
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!