How to use values from excel file in genetic algorithm
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello
Im trying to minimise the total cost incurred to bread retailer by optimising maximum level of bread stored by retailer.
Im using genetic algorthim. I have randomly generated demand values in an excel file that i need to read into so i can change the sets of 30 days of demand. I used readtable function, but the end data type doesnt seem to be compatible with the genetic algorithm.
Error using ()
Subscripting into a table using one subscript (as in t(i)) is not supported. Specify a row subscript and a variable subscript, as in t(rows,vars). To select variables, use t(:,i) or for one variable t.(i). To select rows, use t(i,:).
Error in Copy_2_of_totalCostFunction (line 9)
D = Demand(1:30);
Error in optim.problemdef.fcn2optimexpr
Error in optim.problemdef.fcn2optimexpr
Error in fcn2optimexpr
Caused by:
Function evaluation failed while attempting to determine output size. The function might contain an error, or might not be well-defined at the automatically-chosen point. To specify output size without function evaluation, use 'OutputSize'.
I want to avoid copying and pasting 50 sets of demand data from the source file.
note:
Ive attached the code:-
Copy_2_of_check2 is the genetic algorithm
Copy_2_of_totalCostFunction is the objective function (where demand data is going)
InventoryUpdate is the accessory to the objective function
CSVdemand is the file that has the numbers to take for demand
0 commentaires
Réponse acceptée
Star Strider
le 6 Mar 2024
It produces a matrix that can be addressed just as any other matrix.
For example, to create the ‘D’ vector —
A = readmatrix('CSVdemand.csv')
D = A(:,1) % Read Column Vector
D = A(:,1).' % Transpose To Row Vector
.
.
2 commentaires
Star Strider
le 11 Mar 2024
As always, my pleasure!
Thank you for the following up with your corrections as well.
Plus de réponses (1)
Dheeraj
le 4 Mar 2024
Hi,
I understand you want to access data from CSV file in MATLAB to use in a custom algorithm.
It seems like the error you're encountering is due to how you're trying to access data from the table obtained through “readtable”. You need to access the table's columns using variable names rather than indices.
There are multiple ways to access table data, these are few examples
% Using variable names
T.Var2(2) % access 2nd element in column Var2
T.Var2(5) = T.Var3(4); % assign 4th entry in column 3 to 5th entry in column 2.
% Using brace indexing
T{2,2} % access 2nd element in 2nd column
T{5,2) = T.{4,3}; % assign 4th entry in column 3 to 5th entry in column 2.
You could go through the below documentation to know how to access table data in MATLAB.
Voir également
Catégories
En savoir plus sur Genetic Algorithm dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!