I am trying to build a 4D matrix from a velocity time series so that I can use it as an input to another program. My wind field is a M*N matrix where M is the number of points on the square grid and N is the measurement time in seconds (sampling at 1 hz). I now want to build a 4D array following which should look like this
4D_matrix=[time(1*N) velocity(M*N) x_coord(M,1) y_coord(M,1)];
How do i write this?
Thank you, Ananth

댓글 수: 5

Rik
Rik 2017년 6월 13일
Have you looked into reshape?
If that doesn't help you, what dimensions should this 4D matrix have? (N,M*N,M,M)? You can generate an empty matrix with these dimensions with zeros(N,M*N,M,M) or ones(N,M*N,M,M) and then fill it with a loop if you can't make it work any other way.
Anantha Padmanabhan
Anantha Padmanabhan 2017년 6월 13일
Hello, I have tried this already but I get an error that my array size exceeds maximum array size preference as the number of points M=676 and time N=600. Is there a way around this?
KSSV
KSSV 2017년 6월 13일
What could be the sizes of M and N? If you create 4D matrix, you may end up with memory.
Anantha Padmanabhan
Anantha Padmanabhan 2017년 6월 13일
As said, M=676 (number of grid points) N=600 (for 10 minute simulations)
Faqih Romi
Faqih Romi 2021년 8월 4일
d=[2 3 4 1; 3 2 1 4];
dd(:,:,:,1)=d(1,:,1);
dd(:,:,:,2)=d(2,:,1);

댓글을 달려면 로그인하십시오.

답변 (2개)

Guillaume
Guillaume 2017년 6월 13일

2 개 추천

Well, you need 676^3 * 600^2 * 8 bytes ~= 890 TB of memory to store that many elements, regardless of the shape. Chances are you don't have a computer with that much memory (not even in the ballpark).
You need to rethink what you want to do. In particular, I would think that x_coord and y_coord correspond to the rows and columns of your velocity field, therefore it does not make sense to store them in additional dimensions of the same matrix (as that would wastefully repeat the same values).
Pawel Tokarczuk
Pawel Tokarczuk 2017년 6월 13일

0 개 추천

I think what you need is something like:
Velocity = zeros([NROWS, NCOLS, NTIMES], 'double');
[ X, Y ] = meshgrid(0:NCOLS-1, 0:NROWS-1);
XX = X0 + ScaleX*X;
YY = Y0 + ScaleY*Y;
T = double(0:NTIMES-1);
TT = T0 + ScaleT*Time;
Note the order of the indices (column-major in the first two dimensions, last index varies most slowly).
Those should be the basic data structures; now, you just need to use them appropriately.
IHTH

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

질문:

2017년 6월 13일

댓글:

2021년 8월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by