How can I generate an array that keeps all the values related to specific indices keeps the zero as reference value?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Seba.V
le 21 Août 2019
Réponse apportée : Ted Shultz
le 21 Août 2019
Given the array x=[ -2 -1 0 1 2 ] with respective array y=[2 1 3 5 4] and a value n=2
How can I generate a code that divides all the numbers of x by n, and generates a new array with only the values resulting from the division that are integers?
How can i then generate a new y array where only the values that were related to the (x/n = integers values) are included?
ie: if x=[ -2 -1 0 1 2 ], y=[2 1 3 5 4] and n=2
new_x=[ -1 0 1 ], new_y= [ 2 3 4 ]
or if
x=[ -3 -2 -1 0 1 2 3 ], y=[7 2 1 3 5 4 6] and n=3
new_x=[ -1 0 1 ], new_y= [ 7 3 6]
I hope it makes sense!
Thank you in advance
0 commentaires
Réponse acceptée
Ted Shultz
le 21 Août 2019
The following code does what you want for the values you gave as examples
hope this helps,
--ted
y=[2 1 3 5 4]
x=[ -2 -1 0 1 2 ]
n=2
tempX=x/n; % find x/n
keepIndex = tempX==floor(tempX); % find locations where these are integers
newX= tempX(keepIndex) % only keep values at those locations
newY=y(keepIndex)% only keep values at those locations
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!