Changing data from a list to a matrix

조회 수: 17 (최근 30일)
Eric Wu
Eric Wu 2022년 6월 20일
댓글: Eric Wu 2022년 6월 21일
I have a list of data, 4 columns representing independent variables and the 5th column representing the value f(w,x,y,z). Data exists for every value of the independent variable in the desired range, through interpolation.
Is there an efficient way to change this data into a 4-dimensional array? I am trying to use it as table data in a 4-D lookup table.
Thanks.

채택된 답변

the cyclist
the cyclist 2022년 6월 21일
Can we make a simplified example, to understand what you mean? Suppose you just have 3 columns of data, and your function is f(x,y).
The "list" (i.e. 2-D array) of data is something like,
list = [1 1 5;
1 2 7;
1 3 11;
2 1 13;
2 2 17;
2 3 19];
where the three columns are [x, y, f(x,y)]. Is that right?
And so the output in this case would be a 2-D array of size 2*3, which you get by doing
out = reshape(list(:,end),[3,2])
out = 3×2
5 13 7 17 11 19
If all that is correct, then I think what you want is
out = reshape(list(:,end),[nz,ny,nx,nw])
where the n's are the counts of the number of elements in each dimension.
This solution makes assumptions about the fact that the original list is ordered in a certain way. The solution is more complicated if it is not.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by