- There's no point in having B,C,D,E as input arguments to the function if you're going to define them internally -- either pass the input vectors or remove the arguments
- B=1:1:10 --> [1 2 3 ... 9 10] which are only integer values so I fail to see where the problem would be?
How can I make a function be run with only teenager variables in matlab
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
R@SH
el 21 de Oct. de 2021
Comentada: dpb
el 21 de Oct. de 2021
Dear All,
I have a function with four variables. I want this function be run with only integer variabes. I want to define a bound for each variable and let it run within those span to find the best answer. I dont know how to define the variables to be limited to integers and not other values. for exaple:
Function (A)= optim(B,C,D,E)
B=1:1:10:
C=1:1:10:
D=2:2:10:
E=73:1:77:
It is noted that I am going to run this on Genetic algorithm toolbox. In there I have to determine the upper and lower bound of each parameter. But my problem is that it would be run with all poosible values between the upper and lower bound. I want them to be integer only. How can I do that?
I would appreciate your support in this matter
2 comentarios
dpb
el 21 de Oct. de 2021
Respuesta aceptada
Image Analyst
el 21 de Oct. de 2021
Try this:
function A = optim(B, C, D, E)
% Clip values to a defined range
B = max([1, B]); % Clip so there are no values lower than 1.
B = min([10, B]); % Clip so there are no values more than 10.
% Round to nearest integer.
B = round(B);
% Clip values to a defined range
C = max([1, C]); % Clip so there are no values lower than 1.
C = min([10, C]); % Clip so there are no values more than 10.
% Round to nearest integer.
C = round(C);
% Clip values to a defined range
D = max([2, D]); % Clip so there are no values lower than 2.
D = min([10, D]); % Clip so there are no values more than 10.
% Round to nearest integer.
D = round(D);
% Clip values to a defined range
E = max([73, E]); % Clip so there are no values lower than 73.
E = min([77, E]); % Clip so there are no values more than 77.
% Round to nearest integer.
E = round(E);
2 comentarios
dpb
el 21 de Oct. de 2021
I don't have the TB but what see the doc at https://www.mathworks.com/help/gads/mixed-integer-optimization.html?searchHighlight=integer%20optimization&s_tid=srchtitle_integer%20optimization_1 that illustrates how to set integer constraints on variables.
NB: the limitations on the types of problems that can be solved when doing this.
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!