Indexing a sub-variable in Matlab base workspace

1 次查看(过去 30 天)
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);

采纳的回答

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

更多回答(1 个)

KSSV
KSSV 2021-11-22
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.

类别

Help CenterFile Exchange 中查找有关 Operators and Elementary Operations 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by