please help, I used the retime function to change my gridded temperature data from daily to yearly. I tried plotting the data using pcolor but got the error (color data input must be a matrix) How can I plot this data?

댓글 수: 6

Walter Roberson
Walter Roberson 2021년 6월 29일
After you use retime() what is the size of the data part of the result ?
Lemea Akara
Lemea Akara 2021년 6월 29일
편집: Lemea Akara 2021년 6월 29일
@Walter Roberson. It has a size of (45 * 1) where 45 is the years.. The grid point is 900 but the file size still show (45 * 1) instead of (45*900). I a retime of the data from daily to yearly so, I can plot the data on a Shapefile with x,y coordinate.
Walter Roberson
Walter Roberson 2021년 6월 29일
pcolor() is only for 2 dimensional data grids, never for vectors.
What is the size() of the timetable object ? Please show your code to retime()
Lemea Akara
Lemea Akara 2021년 6월 29일
편집: Walter Roberson 2021년 6월 29일
Load 2_temp_data.mat
dt=(datetime(1970,01,01) :datetime(2014,12,31))';
T = timetable (dt,temp_data);
yearlytemp = retime(T, 'yearly', 'sum')
This is the code I used to retime the data.
The 2_temp_data.mat have two separate data.
(1) Temp_data with size (16435 * 900) the temp. data was collected on a daily basis(16435 days) for 900 grid points
(2) Grid (900 * 2)
. Instead of getting a (45 * 900) value after retiming the temp_data I got (45 * 1) though wen I opened the table. It has other grid points in the datasets. So I try to use Pcolor to plot the (yearlytemp data) I want to plot on a Shapefile....
This is quite long. I wish you"ll understand. Thanks for your patient @walter Roberson
Walter Roberson
Walter Roberson 2021년 6월 29일
Your dt from above is 1 element longer than 16435. datetime('1-jan-2015')-datetime(1970,1,1) is 16436 days. You lost a day somewhere ??
Lemea Akara
Lemea Akara 2021년 6월 29일
Ohk, it is 16436, that was a typo error. Thank you @walter, I will try the code you sent and surely give a feedback on it.

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2021년 6월 29일

0 개 추천

dt=(datetime(1970,01,01) :datetime(2014,12,31))';
temp_data = randi(9, 16436,900);
T = timetable (dt,temp_data);
yearlytemp = retime(T, 'yearly', 'sum');
yt = yearlytemp{:,1};
p = pcolor(1:size(yt,2), yearlytemp.dt, yt); p.EdgeColor = 'none';

댓글 수: 8

Lemea Akara
Lemea Akara 2021년 6월 30일
편집: Lemea Akara 2021년 6월 30일
Thank you @walter. But I have an issue It seems to work only for January of every year at every grid points. All the figures are on the same range and I got same plot that u got too. I want to analyze it on a Shapefile map with different colors. PS I have a data for grid with a size of 900 * 2
Do I understand correctly that you are indicating that when you do
yearlytemp = retime(T, 'yearly', 'sum');
that the results are correct for all the Januarys but not for any other month?
If so then would it be possible for you to attach your data for investigation? (You might need to zip it)
I do not understand about the 900 * 2 grid? You had said your data was 16436 by 900 ?
Lemea Akara
Lemea Akara 2021년 7월 2일
Thank you so much @Walter, everything is good now, I checked my code again, I missed something. Please how can I analyze the data on a Shapefile that has an x,y coordinate?
I really appreciate you.
Walter Roberson
Walter Roberson 2021년 7월 2일
Perhaps the shapefile could be used as a list of coordinates to create a mask? https://www.mathworks.com/help/images/ref/poly2mask.html
Lemea Akara
Lemea Akara 2021년 7월 3일
I have list of coordinate in a .mat file already. How can I analyze my data on the shape file.
BW = poly2mask(x, y, size(yearlytemp,1), size(yearlytemp,2))
maskedyearly = yearlytemp;
maskedyearly(BW) = nan;
Now hopefully everything outside the shape will be nan.
Lemea Akara
Lemea Akara 2021년 7월 3일
Thank you for all your replies @walter.
I got an error in the third line maskedyearly(BW) = nan;
The error reads; subscripting into table using one subscript is not supported.
BW = poly2mask(x, y, size(yearlytemp,1), size(yearlytemp,2))
maskedyearly = yearlytemp{:,1};
maskedyearly(BW) = nan;

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

질문:

2021년 6월 29일

댓글:

2021년 7월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by