Convert 2D data to 3D matrix

13 次查看(过去 30 天)
BN
BN 2020-2-18
I have a 34200 x 4 table. This table shows the 30 years monthly amount of pr (precipitation) in some latitudes and longitudes. So the columns are lat, lon, date, and pr. I want to convert it to a 3D matrix in this format: longitude x latitude x month. So the output should be longitude x latitude x 360. I wanted to use reshape but an error says I cant using reshape in the table, So I wanted to use table2array then use reshape but another error says:
Unable to concatenate the specified table variables.
Caused by:
Error using datetime/horzcat (line 1334)
All inputs must be datetimes or date/time character vectors
or date/time strings.
Also, I'm not sure how I can build a correct 3D matrix because I have many latitude and longitude that have different pr value every month. Do you have any Idea? Thanks
  2 个评论
Raymond MacNeil
Raymond MacNeil 2020-2-18
编辑:Raymond MacNeil 2020-2-18
Do you mean you wish to add 'sheets'?
I'm unclear what you want to happen with the PR data. Where do you want this? I see what you mean by 360, however: every 360 rows is a unique set of lat and long coordinates. So, I can see why you'd want 360 sheets.
Specify the size of the matrix you want...
e.g.,
data = [x, y, z]
Then tell us what is contained within a single sheet (the x- and y-dimensions).
BN
BN 2020-2-18
编辑:BN 2020-2-18
Dear Raymond,
Please look at this picture:
when Y is lon, X is lat and time is 360 pages, and numbers are pr. As it is shown non of any latitude and longitud numbers write in 3d matrix, just pr data.

请先登录,再进行评论。

回答(1 个)

KSSV
KSSV 2020-2-18
If T is your Table...you can access the data of the column using T.(1) , T.(2), T.(3) etc.,. If you have column names....you can access using.. T.lon, T.lat, T.date etc......
First convert your date into datevec using datenum, datevec, datetime functions. After conversion, you can filter them using the months. A striaght reshape may not work.
  5 个评论
KSSV
KSSV 2020-2-18
YOu cannot use Reshape like that....
iwant = reshape(matrix,m,n) ;
Read about reshape.
Raymond MacNeil
Raymond MacNeil 2020-2-19
编辑:Raymond MacNeil 2020-2-19
You have not answered my question. Please give a SPECIFIC example of how you would like a single sheet to look, and how you wish to have the data organized.
Is this, perhaps, what you are going for?
30 x 12 x 95 OR 12 x 30 x 95
Where:
30 is the number of unique years in in the data set;
12 is the month of the year
95 is the number of the unique long/lat coordinate sets.
*EDIT*
Okay, if you want time to be your third dimension I can see wh that is 360 (12*30 unique time measurements per lat/long pair), but you have to explain how you want the Pr data to be organized. It cannot be long x lat because that is 95 x 95, and your data do not conform to that structure.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

标签

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by