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
Luca Ferro
Luca Ferro 2023년 1월 16일
where and how is Ca defined?

댓글을 달려면 로그인하십시오.

답변 (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