# How to use 'find' function in matlab

7 visualizaciones (últimos 30 días)
Atinesh Singh el 28 de Mzo. de 2017
Comentada: KSSV el 28 de Mzo. de 2017
In the below code, We have a random population with structures Position (3D array) and Cost. I need to check whether a particular element present in the population If it does then I want to remove it from the population. I'm using 'find' function for doing it. It was working fine with arrays but with structures I'm getting error below error
_ Undefined operator '~=' for input arguments of type 'struct'_
Here is the code
clc; clear all;
varMin = -5;
varMax = 5;
D = 3;
VarSize = [1 D]; % Decision Variables Matrix Size
NP = 3;
empty_individual.Position = [];
empty_individual.Cost = [];
P = repmat(empty_individual, NP, 1);
CostFunction = @(x) sphere(x);
%%Generating random population
for i = 1:NP
P(i).Position = unifrnd(varMin, varMax, VarSize);
P(i).Cost = CostFunction(P(i).Position);
end
xi = [1 1 1]; % xig
P = P(find(P ~= xi));
##### 4 comentariosMostrar 2 comentarios más antiguosOcultar 2 comentarios más antiguos
KSSV el 28 de Mzo. de 2017
You have to mention what you are expecting actually?
Atinesh Singh el 28 de Mzo. de 2017
I need to check whether a particular element present in the population If it does then I want to remove it from the population

Iniciar sesión para comentar.

KSSV el 28 de Mzo. de 2017
idx = 1:length(P) ;
P = P(find(idx ~= xi));
##### 6 comentariosMostrar 4 comentarios más antiguosOcultar 4 comentarios más antiguos
Atinesh Singh el 28 de Mzo. de 2017
is there any other way to do it
KSSV el 28 de Mzo. de 2017
Define xi as a structure..And try using ismemeber etc.

Iniciar sesión para comentar.

### Categorías

Más información sobre Poisson Distribution en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by