plotting x vs y data ?

조회 수: 12 (최근 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
Michael Haderlein 2015년 3월 9일
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
Michael Haderlein 2015년 3월 9일
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