To allow this code to work, I copy over your data.
resistor_R = [100 220 330 1000 10000 100000 1000000];
I think that you need to be more careful in defining your optimization variable:
resistor_idx = optimvar('resistor_idx',"Type","integer","LowerBound",1,"UpperBound",7);
Also, I don't think that led_I is an optimization variable. So remove the line
You need to create an optimization problem for maximization.
prob = optimproblem("ObjectiveSense","max");
You need to use fcn2optimexpr to create your objective, because you cannot use an optimization variable as an index.
fun = fcn2optimexpr(@(x)(source_V - led_V_forward) /resistor_R(x),resistor_idx);
Put the constraints in the problem.
prob.Constraints.led = fun <= source_I_max;
prob.Constraints.led2 = fun <= led_I_max;
Solve the problem like this:
You see that integer-constrained problems are not so simple to set up. But you can do it if you are careful to follow the limitations.
MATLAB mathematical toolbox documentation