Changing data from a list to a matrix

16 vues (au cours des 30 derniers jours)
Eric Wu
Eric Wu le 20 Juin 2022
Commenté : Eric Wu le 21 Juin 2022
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.

Réponse acceptée

the cyclist
the cyclist le 21 Juin 2022
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 commentaire
Eric Wu
Eric Wu le 21 Juin 2022
@the cyclist this is very helpful, thanks!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by