Repeat operation and change values ​​of an array

3 vues (au cours des 30 derniers jours)
Riccardo Rossi
Riccardo Rossi le 27 Nov 2018
Rouvert : Guillaume le 14 Déc 2018
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 commentaires
Bob Thompson
Bob Thompson le 27 Nov 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
Guillaume le 28 Nov 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?

Connectez-vous pour commenter.

Réponses (1)

Guillaume
Guillaume le 27 Nov 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

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by