Converting FEA data as table into n-D gridded-data Array for Use with 'griddedInterpolant'
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
I have a dataset represented by table obtained from FE Analyses for flux linkage and i want to process this raw data into proper format through MATLAB scripting (as Look up table), where this raw data conaines parametric sweep

I would like to convert this 4-Colomn table into gridded data set in form of 3D Aarry v=(x,y,z), where x,y,z are the first three colomns and the last colomn is v. then i want to process the data with 'griddedInterpolant' to get finer gidded data. The complete dataset provides all of the information needed to create a gridded data set.
Accepted Answer
Matt J
on 22 Mar 2024
x=unique(t{:,1}); nx=numel(x);
y=unique(t{:,2}); ny=numel(y);
z=unique(t{:,3}); nz=numel(z);
v=permute( reshape(t{:,4},[ny,nx,nz]) ,[2,1,3]);
F=griddedInterpolant({x,y,z}, v)
8 Comments
Thank you for your comment. that is good soluation. i think the usage of griddedInterpolant is unusful sense we interpolate with the same grid data (x,y,z), right? we might define a new grid and then use this function.
i am trying to plot the results but seems not working, do you have an idea?
f1=figure(1);
surf(x, y, squeeze(v(:,:,end)));hold on;
Thank you for your comment. that is good soluation.
You are quite welcome, but please Accept-click the answer with the green button to indicate so.
i think the usage of griddedInterpolant is unusful sense we interpolate with the same grid data (x,y,z), right?
I think you misunderstand. The code I showed you hasn't done any interpolation yet. If you want to upsample v to a finer, grid (for example 2x in all dimensions), you would do,
x=unique(t{:,1}); nx=numel(x);
y=unique(t{:,2}); ny=numel(y);
z=unique(t{:,3}); nz=numel(z);
v=permute( reshape(t{:,4},[ny,nx,nz]) ,[2,1,3]);
F=griddedInterpolant({x,y,z}, v);
X=linspace(min(x), max(x), 2*nx);
Y=linspace(min(y), max(y), 2*ny);
Z=linspace(min(z), max(z), 2*nz);
V=F({X,Y,Z}) %interpolated v
To plot the the k-th slice of this result as a surface, you would do
surf(X,Y,V(:,:,k)')
Abdullah
on 27 Mar 2024
Thank you Matt. it worked
but i am wondering why you put ny and then nx in the permute function?
i tryied to exchange between x with y and y with z , but did not work, any idea?
i mean something like this:
v=permute( reshape(t{:,4},[nx,ny,nz]) ,[2,1,3]);
or
v=permute( reshape(t{:,4},[nx,ny,nz]) ,[3,2,1]);
Abdullah
on 31 Mar 2024
any comment Matt?
Matt J
on 31 Mar 2024
Your table shows that y is the coordinate that changes most quickly as you move through the data, then x, then z
This is because i applied a Parametric sweep run in FEA, but i tryied not to sort the data according to the first colomon, so that the first colomn 'x coordinate' changes most quickly, rather than y coordinate.
i used this code, and the results are in the figured attached
[~, index] = sort(If);
If = If(index);
IPeak = IPeak(index);
Beta = Beta(index);
Landa_d = Landa_d(index);
t{:,1}=If';
t{:,3}=Beta';
t{:,2}=IPeak';
t{:,4}=Landa_d';

do you think this will still not work?
It will work, but you will need,
v=permute( reshape(t{:,4},[nx,nz,ny]) ,[1,3,2]);
since now the y-coordinate varies the slowest.
You could also just presort with,
t=sortrows(t,[3,2,1]);
v=reshape(t{:,4},[nx,ny,nz]);
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)