Projection problem as a for loop

2 次查看(过去 30 天)
ISABELLE GUNDRUM
ISABELLE GUNDRUM 2023-1-16
移动Matt J 2023-1-16
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

回答(1 个)

John D'Errico
John D'Errico 2023-1-16
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 个评论
ISABELLE GUNDRUM
ISABELLE GUNDRUM 2023-1-16
移动:Matt J 2023-1-16
Ca is a matrix of many 3D coordinates. I want it to subtract coord_o from each coordinate in the matrix as individual vectors.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by