1

I am trying to build a finantial application that handle economical data using Matlab. The file I want to load is in a csv file and are double numbers in this format '1222.3'. So far, I am just working with one dimension and I am able to load the data into a vector.

The problem is that the data is loaded into the vector in String format. To change all the vector into double format I use str2double(vector), but the numbers into the vector end like this:

1222.3 -> 1.222
153.4 -> 0.1534

I have tried to multiply the vector per 100 (vector.*100), but did not work.

Any idea?

5
  • Are you sure you're not misreading the variable contents? My guess is MATLAB is printing 1.222e+03 Mar 2, 2015 at 13:34
  • It would be a lot better if you posted a complete but minimal example of what you are trying to do. It's quite difficult to isolate your problem as the question stands..
    – kkuilla
    Mar 2, 2015 at 13:35
  • if somewhere in the vector there's a number that's ~1000 times larger than the others, it will all get the e3 suffix. You can easily check for this by typing x(1), where x is your vector. That should then show the correct value. Mar 2, 2015 at 13:39
  • @WouterKuijsters What if the x(1) is ~1000 times larger than the others? Do you not mean max(x(:)) and min(x(:))?
    – kkuilla
    Mar 2, 2015 at 13:43
  • @kkuilla: What I meant is that if you specifically ask for a single value, you will always get the suffix if there is one (and thus check if that specific value was converted correctly). If you have a really long vector of, say, 1e4 entries or so, it can be cumbersome to scroll all the way to the top of the command window to check if there is a common suffix for your vector. Plus, many people seem to overlook this common suffix. Mar 2, 2015 at 13:45

2 Answers 2

1

If your vector components are sufficiently large enough, MATLAB will print the numbers in exponential format.

>> a = 1234.56

a =

   1.2346e+03

The numbers are also shown in scientific notation in the workspace browser:

exponential format in workspace browser

You can print the numbers in decimal form using e.g. fprintf:

>> fprintf('%5.3f\n',a)
1234.560
>>

As a side note, 1.222 * 100 ≠ 1222 ...

0

Matlab automatically pulls some common factor out numerical vectors, which has confused me many times myself. The line that gives the common factor is easy to miss, especially for large vectors, because it is displayed at the top.

If I define a vector with the two number you gave, Matlab displays it to me in the following way:

Matlab number formatting

It pulled out a factor of 1000, as indicated by the line 1.0e+03 *.

1
  • That's it! My vector was too large so I never reached the top.
    – ThomasDE
    Mar 2, 2015 at 20:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.