Borrar filtros
Borrar filtros

Assignment has more non-singleton rhs dimensions than non-singleton subscripts

1 visualización (últimos 30 días)
I am trying to execute a loop and getting this error how can i get out of it
% distanceOfAllNearestTargets = zeros(numberOfNearestNeighbors, 1);
locationNumberOfAllNearestTargets = zeros(numberOfNearestNeighbors, 1);
for ii = 1 : 1 : numberOfNearestNeighbors
locationNumberOfAllNearestTargets(ii, 1) = find(distanceOfAllTargetsFromCurrentPosition == min(distanceOfAllTargetsFromCurrentPosition));
distanceOfAllNearestTargets(ii, 1) = distanceOfAllTargetsFromCurrentPosition(locationNumberOfAllNearestTargets(ii));
distanceOfAllTargetsFromCurrentPosition(locationNumberOfAllNearestTargets(ii, 1)) = max(distanceOfAllTargetsFromCurrentPosition);
end
  8 comentarios
muhammad ahmad
muhammad ahmad el 31 de Oct. de 2018
@madhan Ravi, I have a quite complex code it is just a function of that code.in which I need to generate an array of distances equal to a number of nearest target

Iniciar sesión para comentar.

Respuestas (1)

Rik
Rik el 31 de Oct. de 2018
Editada: Rik el 31 de Oct. de 2018
find is not guaranteed to result 1 value. It might return a vector, or an empty array. If you are certain there will always be 1 result or more, you can use the later inputs to find to limit the results it returns to either the first one or the last one. If that doesn't fit your situation, you should store the find result in a temporary variable and use switch (or if) to handle the three cases (so numel(temp_result)==0, >1, and ==1).
locationNumberOfAllNearestTargets(ii, 1) = find(distanceOfAllTargetsFromCurrentPosition == min(distanceOfAllTargetsFromCurrentPosition),1,'first');
  6 comentarios
muhammad ahmad
muhammad ahmad el 1 de Nov. de 2018
yeah but doing this in a loop cause same error after one iteration
Rik
Rik el 1 de Nov. de 2018
Try to make a small example that reproduces your error. You can attach a mat file with the actual data to your comment if you can't figure out a way to generate some example data.

Iniciar sesión para comentar.

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by