MATLAB: How do you convert numbers to percentages

number to percentpercent

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.

Best Answer

>> 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%