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!