Hello All,
I'm pretty new to matlab and I want to perform a 3D interpolation on a 70 x 7 matrix table. I've read the documentation for 3D but I don't seem to be able to apply it. Here is an example. For instance, if A = 0.33; B = 2.5, what will be the value of C at 75%? Thanks.
A B C
1% 25% 50% 75% 100%
0.30 2 1.1 1.5 1.0 0.3 0.8
0.30 3 1.6 1.8 1.0 0.5 0.8
0.30 4 1.3 1.1 1.0 0.8 0.8
0.30 5 1.2 1.1 1.0 0.6 0.7
0.30 6 1.3 1.1 1.0 0.8 0.7
0.30 7 1.3 1.2 1.0 0.8 0.7
0.30 8 1.3 1.1 1.0 0.8 0.7
0.30 9 1.3 1.1 1.0 0.8 0.7
0.30 10 1.3 1.1 1.0 0.8 0.7
0.30 11 1.8 1.3 1.0 0.8 0.7
0.35 2 1.3 1.8 1.0 0.9 0.1
0.35 3 1.6 1.9 1.0 0.9 0.8
0.35 4 1.4 1.2 1.0 0.9 0.8
0.35 5 1.2 1.1 1.0 0.8 0.8
0.35 6 1.4 1.2 1.0 0.8 0.7
0.35 7 1.3 1.1 1.0 0.8 0.7
0.35 8 1.2 1.1 1.0 0.8 0.7
0.35 9 1.3 1.5 1.0 0.8 0.7
0.35 10 1.9 1.4 1.0 0.8 0.7
0.35 11 1.3 1.1 1.0 0.8 0.8

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2015년 11월 21일
편집: Andrei Bobrov 2015년 11월 21일

0 개 추천

>> f = fopen('yourdata.txt');
cc = textscan(f,'%f %f %f %f %f %f %f ','HeaderLines',2,'CollectOutput',1 );
fclose(f);
g = cc{:};
[A,B,C] = ndgrid(unique(g(:,1)),unique(g(:,2)),[1 25 50 75 100]);
n = size(A);
V = permute(reshape(g(:,3:end),n([2,1,3])),[2,1,3]);
F = griddedInterpolant(A,B,C,V);
>> out = F(.35,4,1)
out =
1.4000

댓글 수: 3

Ruby pca
Ruby pca 2015년 11월 21일
편집: Ruby pca 2015년 11월 21일
Thanks so much Andrei, it works but I noticed that some interpolations don't give the correct answer. For instance:
out = F(0.35,4,1) returns out as 1.3 instead of 1.4 out = F(0.35,9,25) returns out as 1.1 instead of 1.5
Andrei Bobrov
Andrei Bobrov 2015년 11월 21일
corrected
Ruby pca
Ruby pca 2015년 11월 23일
Thanks! It works perfectly now.

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

추가 답변 (1개)

Andrés Medina
Andrés Medina 2020년 4월 26일

0 개 추천

First of all I want to thank Andrei for his invaluable contribution to the forum. Thanks for the example. Now my question goes. How can I do to be able to repeatedly interpolate with your code?. If I enter a value it works correctly. but not when I try to do it for many values, g in my case is a 5041x7 matrix.
Thanks a lot!!
theta_l=atan(abs(tan (deltal).*cos (gamma1))); %longitudinal angle, in rad
theta_t=atan(tan (deltal).*abs(sin (gamma1))) %transversal angle, in rad
%disp(['Angulo longitudinal = ', num2str(theta_l), ' Angulo transversal = ', num2str(theta_t)])
Z1 = theta_l;
Z11 = reshape(Z1,[1,8760]);
Z2= theta_t;
Z22 = reshape(Z2,[1,8760]);
f = fopen('concentracion_txt.txt');
cc = textscan(f,'%f %f %f %f %f %f %f ','HeaderLines',2,'CollectOutput',1 );
fclose(f);
g = cc{:};
[A,B,C] = ndgrid(unique(g(:,1)),unique(g(:,2)),[1 25 50 75 100]);
n = size(A);
V = permute(reshape(g(:,3:end),n([2,1,3])),[2,1,3]);
F = griddedInterpolant(A,B,C,V);
concentracion = F(Z11,Z22,1)

카테고리

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

질문:

2015년 11월 21일

답변:

2020년 4월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by