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);
0 个评论
采纳的回答
Walter Roberson
2021-11-22
[y(i).Cost, y(i).Sol] = CostFunction(particles(i,:);
[ymin, index] = min([y.Cost]);
0 个评论
更多回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Operators and Elementary Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!