Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

How can I fetch values from 2 vectors of numbers without without changing their format.

2 views (last 30 days)
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?

Answers (2)

Jacob Halbrooks
Jacob Halbrooks on 11 Mar 2014
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

Sagar Damle
Sagar Damle on 11 Mar 2014
a = [7900, 9800; 0.02, 0.05]
fprintf('%d \t\t %g\n',a);
Try this! See help about 'fprintf()' in MATLAB help.

Community Treasure Hunt

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

Start Hunting!