griddata command returns all NaN values

7 ビュー (過去 30 日間)
V
V 2021 年 10 月 15 日
コメント済み: Walter Roberson 2021 年 10 月 16 日
Hi,
I am trying to create a contour plot from X and Y values that correspond to a theoretical temperature (Tt) value. I am trying to use the griddata command to interpolate the data so it can be graphed. But, the command returns NaN for most every value. I could really use some help. Thank you.
W = 6;
L = 5;
X1 = zeros(100,1);
Y1 = zeros(100,1);
Tt = zeros(100,1);
b = 1;
for a = 1:100
X1(a) = (5/200).*a;
c1 = rem(a,50);
if c1 == 0
Y1(a) = (6/200).*b;
b = b + 1;
else
Y1(a) = (6/200).*b;
end
end
end
if a == 100
for m = 1:100
syms m1
Tt_xy = 425.8343968*symsum((2/pi).*(((-1).^(m1+1)+1)./m1).*sin(m1.*pi.*(X1(m)./L)).*(sinh(m1.*pi.*(Y1(m)./L))./sinh(m1.*pi.*(W./L))),m1,[1 5]);
Tt(m) = Tt_xy;
end
end
n1 = 100;
[x1,y1] = meshgrid(linspace(.0250,5,n1),linspace(.03, 6,n1));
f2 = griddata(X1,Y1,Tt,x1,y1);
f3 = figure;
[C1, h1] = contour(x1,y1,f2);
clabel(C1,h1);
  2 件のコメント
V
V 2021 年 10 月 15 日
No I do not need symbolic variables. I need numerical variables. Is that where I am making a mistake? If so I'm not sure how to fix that? Sorry I'm not the greatest at MatLab.

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

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 10 月 15 日
for a = 1:100
X1(a) = (5/100).*a;
X1 is linear in a.
c = a/50;
a is a double precision integer, 1 to 100. c is the integer divided by 50. c will always be real-valued.
c1 = isreal(c);
if c1 == 1
so that branch is always going to be taken
Y1(a) = (6/100).*b;
Y1 in this branch is linear in b. But this branch is the only one that can get executed, so all Y1 are linear in b.
b = b + 1;
and b is increment by 1 each time the branch is met. But the branch is met every iteration. So every time, through, b will be the same as a at the time of the calculation of Y1. So X1 and Y1 are both linear in a .
else
Y1(a) = (6/100).*b;
This branch is never executed.
end
end
Your X1 and Y1 are now the same as if you had done
a = 1:100;
X1 = (5/100) .* a;
Y1 = (6/100) .* a;
This is a straight line of values, not even one value that is off of the line.
Later, you interpolate over an entire grid. But the values to interpolate from are strictly co-linear. There is no information available for sidewise movement, so everything off-line that is interpreted is going to be NaN.
  2 件のコメント
Walter Roberson
Walter Roberson 2021 年 10 月 16 日
griddata() was the wrong function for that situation.
W = 6;
L = 5;
X1 = zeros(100,1);
Y1 = zeros(100,1);
Tt = zeros(100,1);
b = 1;
for a = 1:200
X1(a) = (5/200).*a;
c1 = rem(a,50);
if c1 == 0
Y1(a) = (6/200).*b;
b = b + 1;
else
Y1(a) = (6/200).*b;
end
end
if a == 200
for m = 1:200
syms m1
Tt_xy = 425.8343968*symsum((2/pi).*(((-1).^(m1+1)+1)./m1).*sin(m1.*pi.*(X1(m)./L)).*(sinh(m1.*pi.*(Y1(m)./L))./sinh(m1.*pi.*(W./L))),m1,[1 5]);
Tt(m) = Tt_xy;
end
end
n1 = 50;
[x1,y1] = meshgrid(linspace(.0250,5,n1),linspace(.03, 6,n1));
%f2 = griddata(X1,Y1,Tt,x1,y1);
F = scatteredInterpolant(X1, Y1, Tt);
f2 = F(x1, y1);
f3 = figure;
[C1, h1] = contour(x1,y1,f2);
axis([0.001 5 0.001 6]);
clabel(C1,h1);

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

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by