Effacer les filtres
Effacer les filtres

how to convert a vector to a number

3 vues (au cours des 30 derniers jours)
Itzik Ben Shabat
Itzik Ben Shabat le 16 Déc 2012
hi lets say i have a vector [1,1,1] is there a function that can convert this to the number 111 ?
  2 commentaires
Walter Roberson
Walter Roberson le 16 Déc 2012
What should be done if the vector includes values greater than 9?
If the vector starts with values that are 0, what should be the result ?
Itzik Ben Shabat
Itzik Ben Shabat le 16 Déc 2012
the vector does not contain values greater than 9. if it has 0 to the left it ignores them - 009=9, 012=12 etc.
i could write a for loop that calculates this but i was wondering if there is a function.

Connectez-vous pour commenter.

Réponse acceptée

José-Luis
José-Luis le 16 Déc 2012
Modifié(e) : José-Luis le 16 Déc 2012
a = randi(9,1,5);
your_num = sscanf(sprintf('%d',a),'%d');
or
alt_sol = sum(a.*repmat(10,1,numel(a)).^(numel(a)-1:-1:0));

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB 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!

Translated by