Search code examples
csvimportscientific-notation

correct scientific notation on CSV import into MATLAB


I have a set of numerical data in a CSV file that is accompanied with a letter which denotes the mathematical notation for the associated number such as 'm' for milli, 'n' for nano.

for example

190.4 n
100.7 n
20.3 n
9.5 m

ect

Now when I import into MATLAB in a comma column delimiter in a numerical matrix, the scientific notation is dropped and the number is produced in a cell, unfortunately MATLAB has not taken into account the alphabetical notation and therefore the numerical data is erroneous.

Is there any way to allow the conversion into the full numerical value taking into account the notation?


Solution

  • Use the system command to shell out to the operating system and invoke awk or similar to make sense of and reformat your input data.

    Something like this (untested)

    awk '/m/ {print $1/1000}
         /n/ {print $1/1000000000} ' stupid.csv > sensible.csv