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
Walter Roberson
Walter Roberson 2021 年 7 月 1 日
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.
Walter Roberson
Walter Roberson 2021 年 7 月 3 日
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.
Walter Roberson
Walter Roberson 2021 年 7 月 3 日
BW = poly2mask(x, y, size(yearlytemp,1), size(yearlytemp,2))
maskedyearly = yearlytemp{:,1};
maskedyearly(BW) = nan;

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by