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.
  1 件のコメント
Eric Wu
Eric Wu 2022 年 6 月 21 日
@the cyclist this is very helpful, thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing 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