Search code examples
matlabmatlab-figure

How can i use a text file to create a figure in matlab?


I have row data in a text file that looks like this:

2.40 2.22 5.48 -5.93 -3.67 5.84 0.70 1.44 3.26 -12.27 -5.65 0.81 -1.17 5.83 5.50 -1.67 7.10 -7.14 1.25
1.47 15.78 -10.79 0.70 -1.58 3.77 4.67 3.62 -2.19 3.43 2.82 -0.52 -1.61 6.30 3.57 6.06 8.07 2.03 2.95
2.64 -3.78 -12.95 2.73 -2.18 -1.16 0.35 6.90 5.57 -1.64 1.45 8.78 2.27 -1.03 0.91 0.64 0.02 1.93 2.14
6.19 1.87 12.23 -7.71 14.92 1.30 -1.04 0.93 6.75 4.91 21.72 4.22 4.02 -0.16 2.06 1.89 0.23 0.91 4.36
-0.03 -2.78 0.79 -5.98 -0.18 -1.19 5.57 -7.95 1.95 2.86 2.85 -6.89 -0.53 -6.59 2.14 3.75 1.22 2.49 1.72
5.52 -4.71 -5.38 -7.50 4.21 3.38 4.14 0.92 -2.23 -13.98 0.98 1.45 -3.50 3.04 -5.04 -1.35 -6.37 -3.57 -1.96
-0.62 0.86 -1.99 -10.95 7.00 -1.85 5.00 -1.33 -1.50 -0.69 10.36 4.60 -4.69 4.19 7.17 -0.74 5.00 5.53 -3.02
1.91 1.85 -7.72 -2.67 3.62 -0.52 -1.13 4.40 -2.64 1.26 3.40 -3.17 -10.48 -2.22 -1.04 0.64 -5.93 2.47 -0.86
-0.12 -8.24 -11.59 -15.03 -3.21 3.27 5.67 5.21 -0.40 -12.33 0.62 8.42 -5.89 3.03 4.07 -0.16 -4.43 1.78 2.12
8.09 -3.20 6.90 12.89 8.92 -0.01 -1.97 4.53 -1.92 -17.77 4.76 0.04 8.83 -1.41 1.73 1.55 6.93 -0.95 0
11.80 -6.92 11.79 12.82 0.42 5.93 4.01 -0.94 -6.49 -2.12 -0.01 1.43 -1.41 3.09 2.27 3.36 3.63 1.44 0
16.23 -2.27 1.66 -12.50 3.10 0.66 5.93 8.31 -2.00 3.69 1.91 5.86 1.11 2.05 2.09 1.06 -4.03 2.92 0 

Each column represents a year from 1999 to 2017 in order (going from left to right) and each row represents a month from Jan to December in order (going top to bottom).

I have to write a code that transforms this data to a figure. The code needs to be as general as possible so that any other data can be added and still run the code. The biggest problem I'm having is how I have to assign the columns to years and the rows to months. The following is a link to a pdf file containing the figure and the data file https://www.dropbox.com/s/bgzg6lbpr3t0ib9/Inl%C3%A4mningsuppgift2_HT17%20%281%29.pdf?dl=0


Solution

  • The easiest way to import the data in a general way would be to use the graphical Matlab import tool

    uiimport
    

    select output type as "Numeric Matrix"

    then you have your data in this example as 12x19 double

    rehape the array to a vector can be done in this case just by data(:)

    figure;plot(data(:))