Convert 2D data to 3D matrix

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 Kommentare

Raymond MacNeil
Raymond MacNeil am 18 Feb. 2020
Bearbeitet: Raymond MacNeil am 18 Feb. 2020
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 am 18 Feb. 2020
Bearbeitet: BN am 18 Feb. 2020
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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

KSSV
KSSV am 18 Feb. 2020

1 Stimme

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 Kommentare

BN
BN am 18 Feb. 2020
Bearbeitet: BN am 18 Feb. 2020
Dear KSSV, Is that right?
locations_lat = unique(C.lat, 'stable');
locations_lon = unique(C.lon, 'stable');
dates = unique(C.date, 'stable');
I want to reshape this to achieve a 3d matrix. I don't want latitude and longitude numbers and time is in my matrix. I just want pr data in a matrix. Just like when we open a NetCDF data that is a 3d matrix.
KSSV
KSSV am 18 Feb. 2020
How you reshape?
BN
BN am 18 Feb. 2020
newC=reshape(locations_lat, locations_lon, pr, dates);
% And here is error:
Dot indexing is not supported for variables of this type.
Error in datetime/reshape (line 1360)
this.data = reshape(this.data,varargin{:});
KSSV
KSSV am 18 Feb. 2020
YOu cannot use Reshape like that....
iwant = reshape(matrix,m,n) ;
Read about reshape.
Raymond MacNeil
Raymond MacNeil am 19 Feb. 2020
Bearbeitet: Raymond MacNeil am 19 Feb. 2020
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Type Identification finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2018b

Gefragt:

BN
am 18 Feb. 2020

Bearbeitet:

am 19 Feb. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by