Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

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

조회 수: 1 (최근 30일)
Marina
Marina 2014년 3월 11일
마감: MATLAB Answer Bot 2021년 8월 20일
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?

답변 (2개)

Jacob Halbrooks
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

Sagar Damle
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.

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by