plotting x vs y data ?

10 次查看(过去 30 天)
Natasha
Natasha 2015-3-9
回答: Natasha 2015-3-10
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

回答(2 个)

Michael Haderlein
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 个评论
Natasha
Natasha 2015-3-9
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
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.

请先登录,再进行评论。


Natasha
Natasha 2015-3-10
Thank you for your help

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by