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!