Repeat operation and change values ​​of an array

3 次查看(过去 30 天)
Riccardo Rossi
Riccardo Rossi 2018-11-27
重新打开: Guillaume 2018-12-14
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
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
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
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

类别

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

标签

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by