Convert python code to matlab code
Mostrar comentarios más antiguos
I need to convert following python codes to Matlab. Can anyone help me to convert following codes.
for i in range(0,PopSize):
#pos[i,:]=checkBounds(pos[i,:],lb,ub)
for j in range(dim):
pos[i, j] = numpy.clip(pos[i,j], lb[j], ub[j])
#Calculate objective function for each particle
fitness=objf(pos[i,:])
Respuestas (1)
Ameer Hamza
el 5 de Abr. de 2020
Something like this
pos(pos < lb) = lb;
pos(pos > ub) = ub;
fitness = zeros(1,PopSize);
for i=1:PopSize
fitness(i)=objf(pos(i,:))
end
Also, see this basic course to get started in MATLAB: https://www.mathworks.com/learn/tutorials/matlab-onramp.html
3 comentarios
Usman Taya
el 5 de Abr. de 2020
Ameer Hamza
el 5 de Abr. de 2020
Can you share your objective function objf and the matrix pos?
Usman Taya
el 6 de Abr. de 2020
Editada: Usman Taya
el 6 de Abr. de 2020
Categorías
Más información sobre Call Python from MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!