Converting FEA data as table into n-D gridded-data Array for Use with 'griddedInterpolant'

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.

 채택된 답변

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

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)')
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]);
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]);

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2024년 3월 22일

댓글:

2024년 4월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by