Effacer les filtres
Effacer les filtres

combining specific elements in an array

12 vues (au cours des 30 derniers jours)
Muhammad Haziq
Muhammad Haziq le 6 Déc 2018
Commenté : Muhammad Haziq le 6 Déc 2018
I have a array containing 9 element, now I want combine every three columns into one so at final I have an array of three elements. can any body help me.
initial_array = [16, 29, 0.599, 16, 30, 0.297, 16,33, 0.178]
final_array=[1629.599, 1630.297, 1633.178]

Réponse acceptée

Stephen23
Stephen23 le 6 Déc 2018
Modifié(e) : Stephen23 le 6 Déc 2018
Assuming that the number of digits is always the same....
Method one: reshape and matrix multiply:
>> V = [16, 29, 0.599, 16, 30, 0.297, 16, 33, 0.178];
>> Z = [100,1,1]*reshape(V,3,[])
Z =
1629.599000000000 1630.297000000000 1633.178000000000
Method two: indexing:
>> Z = 100*V(1:3:end) + V(2:3:end) + V(3:3:end)
Z =
1629.599000000000 1630.297000000000 1633.178000000000
  1 commentaire
Muhammad Haziq
Muhammad Haziq le 6 Déc 2018
Thanks for replying it solve my problem.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Tags

Produits


Version

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by