Repeat operation and change values of an array
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
Bob Thompson
2018-11-27
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
2018-11-28
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?
回答(1 个)
Guillaume
2018-11-27
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!