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!