Info
此问题已关闭。 请重新打开它进行编辑或回答。
How can I fetch values from 2 vectors of numbers without without changing their format.
1 次查看(过去 30 天)
显示 更早的评论
Hi, I am asking for a matrix to return values from 2 vectors: one is the company id (a number), the other one is the return according to the CAPM. Since the company number is quite high (7900,9800 a.s.o.) and the return is low (0.02,0.05,0.07) Matlab seems to standardie them when putting them together. It returns 0.0790, 0.9800 for companies and 0.0000 0.000 for returns. How can I avoid this standardization problem? When I transform The company to string, it returns the same value 32,000 for the whole column besides the last 3 rows, where it retuns 49.000. How can I solve it?
0 个评论
回答(2 个)
Jacob Halbrooks
2014-3-11
You can control how MATLAB displays your data using FORMAT. This is independent of how MATLAB actually stores and handles your data. From the help for FORMAT:
format does not affect how MATLAB computations are done. Computations
on float variables, namely single or double, are done in appropriate
floating point precision, no matter how those variables are displayed.
In the default short format, a matrix with large and small numbers can obscure the small numbers:
>> [7900, 9800; 0.02, 0.05]
ans =
1.0e+03 *
7.9000 9.8000
0.0000 0.0001
Try using one of the other formats. For example:
>> format shorte
>> [7900, 9800; 0.02, 0.05]
ans =
7.9000e+03 9.8000e+03
2.0000e-02 5.0000e-02
1 个评论
Sagar Damle
2014-3-11
a = [7900, 9800; 0.02, 0.05]
fprintf('%d \t\t %g\n',a);
Try this! See help about 'fprintf()' in MATLAB help.
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!