Projection problem as a for loop
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
Réponses (1)
John D'Errico
le 16 Jan 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 commentaire
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!