Effacer les filtres
Effacer les filtres

Transfer from Decimal to Percentage?

14 vues (au cours des 30 derniers jours)
Xiao Tang
Xiao Tang le 25 Juin 2012
Commenté : geopap le 14 Sep 2016
Hi guys,
I have a Matrix A =
[1 2 3
4 5 6
7 8 9]
How I can get Matrix B =
[100% 200% 300%
400% 500% 600%
700% 800% 900%]?
Sprintf might work but I don't know how to use it. Thanks in advance.
  2 commentaires
Walter Roberson
Walter Roberson le 25 Juin 2012
You cannot get it as a numeric matrix, as numeric matrices cannot contain '%' characters.
Xiao Tang
Xiao Tang le 25 Juin 2012
Then how can I transfer it to string or cell array? As long as there follows '%'.
I was wondering if there is a function to do this...

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 25 Juin 2012
thisfmt = [ repmat(' %.3f%%', 1, size(A,2)) '\n'];
B = sprintf( thisfmt, A.' );
B(1) = '[';
B(end) = ']';
This creates the output as a single string.
  8 commentaires
Xiao Tang
Xiao Tang le 27 Juin 2012
Thanks Tom! That's perfect!
geopap
geopap le 14 Sep 2016
Tom this works great!! Thanks

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by