How to plot gridded data

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 Comments

After you use retime() what is the size of the data part of the result ?
Lemea Akara
Lemea Akara on 29 Jun 2021
Edited: Lemea Akara on 29 Jun 2021
@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.
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()
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
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 ??
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.

Sign in to comment.

 Accepted Answer

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 Comments

Lemea Akara
Lemea Akara on 30 Jun 2021
Edited: Lemea Akara on 30 Jun 2021
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 ?
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.
Perhaps the shapefile could be used as a list of coordinates to create a mask? https://www.mathworks.com/help/images/ref/poly2mask.html
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.
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;

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!