Convert 2D data to 3D matrix

조회 수: 9 (최근 30일)
BN
BN 2020년 2월 18일
편집: Raymond MacNeil 2020년 2월 19일
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