How do you convert numbers to percentages?

12 views (last 30 days)
transMatrix = [.02 .01 0 0 .06 -.08; .03 .12 .12 0 .17 -.06; .025 .07 0 .0002 .07 -.03; 0 0 .0002 0 .05 -.02] I would like to change these numbers to percentages.
  2 Comments
jonas
jonas on 4 Sep 2018
What do you mean? What are those numbers currently?
Walter Roberson
Walter Roberson on 4 Sep 2018
Percentage out of the row total? Percentage out of the column total? Percentage out of the entire matrix total?

Sign in to comment.

Accepted Answer

Stephen23
Stephen23 on 4 Sep 2018
Edited: Stephen23 on 4 Sep 2018
>> P = 100 * transMatrix
P =
2.00000 1.00000 0.00000 0.00000 6.00000 -8.00000
3.00000 12.00000 12.00000 0.00000 17.00000 -6.00000
2.50000 7.00000 0.00000 0.02000 7.00000 -3.00000
0.00000 0.00000 0.02000 0.00000 5.00000 -2.00000
You can easily print them with a % symbol:
>> F = sprintf('%s\n',repmat('%8g%%',1,6));
>> fprintf(F,P.')
2% 1% 0% 0% 6% -8%
3% 12% 12% 0% 17% -6%
2.5% 7% 0% 0.02% 7% -3%
0% 0% 0.02% 0% 5% -2%

More Answers (0)

Categories

Find more on Operators and Elementary Operations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!