0
votes

I have a 4032 X 102 matrix (first 2 columns are the coordinates). I would like to interpolate every column by a 48 X 84 meshgrid. It's working column-by-column, but it would be great if it can be done by one command (with a for loop maybe).

x = 1:84; y = 1:48;
[X,Y] = meshgrid(x,y);
Z = griddata(data(:,1),data(:,2),(:,3:102),X,Y'v4');

The input data is also grid data but not in matrix form. My goal is to create map(grid again) from this. So there are X, Y coordinates and values. Each column represent data of a map, and the values along the coordinates.

First 2 columns contain the coordinates of the data point. These are the first 2 row of a map with 4 cell spacing. Z is the gridded data matrix along the 48 x 84 grid. Many thanks!

1
Could you show an example input & output? Since original problem is too big in size to post, could you mock up a smaller one such as 12 (3x4) x 5? - Yvon
The input data is also grid data but not in matrix form. My goal is to create map(grid again) from this. So there are X, Y coordinates and values. Each column represent data of a map. For example: Columns: X = (1 : 84); Y = (1 : 48); and the values along the coordinates. These are the first 2 row of a map with 4 cell spacing. Thanks - Mihail
1) If I understand your problem correctly you want a 48 x 84 matrix out of every column of the 4032 x 102 matrix, so there should be 102 such matrices in total and each of them has one set of data. Then you may use reshape rather than interpolate. 2) I'm still not sure what you mean by the Z (3rd argument is invalid) and "These are the first 2 row of a map with 4 cell spacing" either. - Yvon
Yes, you understood my problem. First 2 columns contain the coordinates of the data point. Z is the gridded data matrix along the 48 x 84 grid. I know the 3rd argument is invalid but I wanted to show my problem with this. And a last sentence is wrong I'm sorry. I wanted to paste here an example but it wasn't failed. - Mihail

1 Answers

0
votes

You can reshape a 4032x1 vector into a 48x84 2-D matrix:

reshape(vector, 48,84)

Since you have 102 of them, and they are already stored in a single matrix variable, you can now store each single matrix in the first two dimensions (1st dim has 48 elements and 2nd has 84) and all 102 matrices are indexed in the third dimension.

reshape(data, 48,84,102)