0
for beta = 0.2:0.1:1
    betas = [0.2   0.3 0.4 0.5 0.6 0.7 0.8 0.9 1];
    cs    = [80000 400 40  12  5   3   2   1   1]; 
    index = find(betas==beta,1);
    c = cs(index); end

Why this find index doesn't work? Ideally c should take every value in cs

ZHU
  • 904
  • 1
  • 11
  • 25

1 Answers1

0

Your beta and betas are doubles. And you should never compare doubles with ==.

E.g. try this:

(1.001-0.001)==1

It will return false.

Here is the correct version of your code:

for beta = 0.2:0.1:1
    betas = [0.2   0.3 0.4 0.5 0.6 0.7 0.8 0.9 1];
    cs    = [80000 400 40  12  5   3   2   1   1]; 
    index = find(abs(betas-beta)<eps,1);
    c = cs(index)
end
kostek
  • 801
  • 2
  • 15
  • 32