Borrar filtros
Borrar filtros

Projection problem as a for loop

4 visualizaciones (últimos 30 días)
ISABELLE GUNDRUM
ISABELLE GUNDRUM el 16 de En. de 2023
Movida: Matt J el 16 de En. de 2023
I am trying to create a loop that finds the mean projection onto the line. The coordinates of the line arfe set, but the coordinate of the vector being projected changes and I need the average projection and standard deviation. I don't have much experience with loops so this is what I have so far. I keep getting an error that says "Error using '-'. Integers can only be combined with integers of the same class, or scalar doubles".
coord_o = [78 132 199];
coord_b = [145 161 184];
vector_b = coord_b - coord_o;
M = size(Ca,1);
for i = 1:M;
coord_a = Ca(i);
vector_a = coord_a(i) - coord_o;
project = dot(vector_a(i),vector_b)/norm(vector_a(i))
disp(mean(project))
end

Respuestas (1)

John D'Errico
John D'Errico el 16 de En. de 2023
Your main problem is that the vector Ca is not composed of double precision numbers. That causes the code to fial, because the further computations you are doing with those numbers involve things that will fail for what are very probably uint8 integers.
So in your for loop, change this:
coord_a = Ca(i);
to this:
coord_a = double(Ca(i));
As well, make sure that coord_o and coord_b are also doubles. Even though you show them here as doubles by default, we do not know they are doubles in your code as you are using them.
  1 comentario
ISABELLE GUNDRUM
ISABELLE GUNDRUM el 16 de En. de 2023
Movida: Matt J el 16 de En. de 2023
Ca is a matrix of many 3D coordinates. I want it to subtract coord_o from each coordinate in the matrix as individual vectors.

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by