plotting x vs y data ?
조회 수: 12 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (2개)
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
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!