Borrar filtros
Borrar filtros

Indexing a sub-variable in Matlab base workspace

2 visualizaciones (últimos 30 días)
Ayobami Meadows
Ayobami Meadows el 22 de Nov. de 2021
Respondida: Walter Roberson el 22 de Nov. de 2021
I do get following when trying to run the code. Error using min. Invalid data type. First argument must be numeric or logical. The concept is that I need to index the y(i).Cost as follow:
[y(i).Cost, y(i).Sol] = CostFunction(particles(i,:);
[ymin, index] = min(y);

Respuesta aceptada

Walter Roberson
Walter Roberson el 22 de Nov. de 2021
[y(i).Cost, y(i).Sol] = CostFunction(particles(i,:);
[ymin, index] = min([y.Cost]);

Más respuestas (1)

KSSV
KSSV el 22 de Nov. de 2021
This line:
[ymin, index] = min(y);
Your input to the function min is a structure. min takes an array as input. You need to change the input. Don't input a structure.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by