Repeat operation and change values of an array
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi everyone, i have an array P 1x3xn.
If the distance between point 1 and point 2 is different from t I have to change the Y of point 2 of Y(2) * f. If the distance between point 2 and point 3 is different from t I have to change the Y of point 3 of Y(3) * f. If the distance of point n-1 and point n is different from t I have to change Y of point n of Y(n) * f.
How can i do it? Thank you so much!
2 comentarios
Bob Thompson
el 27 de Nov. de 2018
I need a bit more information before I can give you a good answer.
How are the points defined within array P?
What is 'f'? A constant?
What do you have so far?
Guillaume
el 28 de Nov. de 2018
Note that angle between points is meaningless. You're calculating the angle between the vectors starting at the origin and ending at your points.
Your original question talked about distance (which is defined for points), now you're talking about angles. I've no idea what your question is about anymore.
Probably it would be better if you explained what your ultimate goal is? Are you trying to generate vectors with a fixed angle between then?
Respuestas (1)
Guillaume
el 27 de Nov. de 2018
As per Bob's comment, we have no idea what f and t are. Assuming they're constant, this is probably what you're after:
P = ???? %1x3xN array
f = ???? %scalar
t = ???? %scalar
tolerance = ???? %appropriate tolerance small enough compared to the magnitude of t, e.g. t / 1e8
deltaP = diff(P, [], 3); %difference in X, Y, Z between points
distance = sqrt(sum(deltaP .^ 2, 2)); %distance between points
ist = abs(distance - t) < tolerance; %distance is equal to t if difference is less than tolerance
P(1, [ist(:); false], 2) = P(1, [ist(:); false], 2) * f; %change Y of points where distance is not equal to t
0 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!