plotting x vs y data ?

7 views (last 30 days)
Natasha
Natasha on 9 Mar 2015
Answered: Natasha on 10 Mar 2015
I want to plot a line graph of temperature (y axis) vs time (years) (x axis).
But my issue is that the temperature data, the x axis data is given monthly therefore there are 12 data points/ 12 temperatures for every one year point/ time point.
For this reason would you possibly know of a way for me to plot x,y when dealing with data that for each y point there are 12 x points.
Thanks
I have attached the data also

Answers (2)

Michael Haderlein
Michael Haderlein on 9 Mar 2015
Sorry, I got a bit confused by the description of the problem. You want to plot this part of the file, right?
Year Jan Feb Nov Dec
1880 -33 -26 -16 -21
1881 -12 -15 -26 -17
1882 4 5 -24 -36
I would read this data to get the matrix representation just like
-33 -26 ... -16 -21
-12 -15 ... -26 -17
4 5 ... -24 -36
, then transpose it and then put it to one long array which will look like
[-33 -26 ... -16 -21 -12 -15 ... -26 -17 4 5 ... -24 -36]'
So now the data is in the correct order and you can plot it. With set(gca,'xtick',...) and set(gca,'xticklabel',{...}), you can also create a reasonable x scale.
  2 Comments
Natasha
Natasha on 9 Mar 2015
I'm normally just used to plotting data that has one y point for every one x point.
So should I get matlab to extract and display the monthly temperature data (how would I extract the specific data e.g. display(:2,:13) all of column 2 to all of column 13?
To then put this data into an array would I have to type every single number?
I apologize I am only beginning to use matlab.
Michael Haderlein
Michael Haderlein on 9 Mar 2015
What do you want to display? I assumed you want to plot all this data in one line, so first point=Jan1880, second point=Feb 1880, 12th point=Dec 1880, 13th point=Jan 1881 etc. I somehow forgot to show you how to do this, assume A is the matrix from the file, then with
A=A';
you transpose and with
Aall=A(:);
you put everything into one long line just as I have written in my first answer.
If you only want to display the data of one year (say, 1882), you plot
plot(A(:,3))
If you want to plot the data of all Novembers, you plot
plot(A(11,:))
This all applies on the transposed array.

Sign in to comment.


Natasha
Natasha on 10 Mar 2015
Thank you for your help

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!