After using griddata, standard deviation is changed.

I rewritten it with the code and data. Thank you.
Hello. Respected seniors.
I'm not familiar with English, so I'm using a translator, so please forgive me if the sentences are weird.
New data was created using grid data for use in other programs.
The maximum and minimum values of the data were made within the expected or acceptable margin of error, but the standard deviation was greatly reduced to create unacceptable figures.
This is the code used.
clear,close all;
Fin=fopen('data1.csv','rt');
if(Fin==-1)
errordlg('File Open Error ! Program stoped!','Error');
error('File Open Error ! Program stoped!');
end
State=0;
radius = 300;
while(~State)
npoints = 2839 ;
A=fscanf(Fin,'%e ',[8,npoints]);
Nx=A(2,:);
Ny=A(3,:);
Nz=A(7,:);
Nx7=Nx ;
Ny7=Ny ;
Nz7=Nz ;
State=feof(Fin);
end
%% make_int
deltaZ = max(Nz) - min(Nz);
X_int = -255:0.9961:255 ;
Y_int = -255:0.9961:255 ;
Y2_int = flip(Y_int);
[xq_int,yq_int] = meshgrid(X_int,Y2_int);
gd_int = griddata(Nx7,Ny7,Nz7,xq_int,yq_int);
gd_int1 = gd_int*(10^5);
gd_int2 = gd_int1;
gd_int3 = round(gd_int2);
gridsize = 512;
for i = 1:gridsize
for j = 1:gridsize
if isnan(gd_int3(i,j))
gd_int4(i,j) = -32767;
else
gd_int4(i,j) = gd_int3(i,j);
end
end
end
M = gd_int4;
dlmwrite('L1_front_gx_codierite_grid512_ssz0.1.int', M , 'delimiter' , ' ' , 'precision' , '%d');
%%
for i = 1:gridsize
for j = 1:gridsize
if isnan(gd_int3(i,j))
gd5(i,j) = 0;
else
gd5(i,j) = gd_int3(i,j);
end
end
end
AB2 = nonzeros(gd5);
%%
for i = 1:gridsize
for j = 1:gridsize
if isnan(gd_int(i,j))
gd6(i,j) = 0;
else
gd6(i,j) = gd_int(i,j);
end
end
end
AB = nonzeros(gd6);
%%
%%figure
%%mesh(xq_int,yq_int,gd_int);
%%hold on
%%plot3(Nx,Ny,Nz,'o');
%%h = gca;
%%h.XLim = [-255 255];
%%h.YLim = [-255 255];
%%colormap('jet')
figure
mesh(xq_int,yq_int,gd_int);
h = gca;
h.XLim = [-255 255];
h.YLim = [-255 255];
colormap('jet')
%%figure
%%surface(xq_int,yq_int,gd_int);
%%h = gca;
%%h.XLim = [-255 255];
%%h.YLim = [-255 255];
%%colormap('jet')
%%
fclose(Fin);
This is a result from code. red box is calculated standard deviation value.
It is the rms value calculated by another code. change the unit, it's 486.7774.
The difference between the two values is fifty.
Can I know if the standard deviation value decreases using the grid data?

6 件のコメント

KSSV
KSSV 2022 年 8 月 9 日
Show us your data and code.
Walter Roberson
Walter Roberson 2022 年 8 月 9 日
Do you mean like this, where std(V) is different from std(Vq) ?
rng(12345)
No = 30;
Nn = 50;
x = randn(1,No);
y = randn(1,No);
V = sin(x) + cos(y);
xvec = linspace(-3, 3, Nn);
yvec = linspace(-3, 3, Nn);
[xq, yq] = ndgrid(xvec, yvec);
Vq = griddata(x, y, V, xq, yq);
scatter3(x, y, V, 'r*');
hold on
scatter3(xq(:), yq(:), Vq(:), 'k.');
hold off
legend({'original', 'interpolated'})
std(V)
ans = 0.9184
std(Vq(:), 'omitnan')
ans = 0.8312
Bruno Luong
Bruno Luong 2022 年 8 月 9 日
編集済み: Bruno Luong 2022 年 8 月 9 日
Your question is strange mathematically.
V and Vq are not noise so how do you interpret std ?
There is a function underlined the interpolation, The
std(Vq) / sqrt(numel(Vq))
approximates perhaps the RMS of the function, but
std(V) / sqrt(numel(V))
would not approximate it, but they should have the same order if V and Vq are more or less sampling the domain X, Y. That is the hint that
std(V) ~ RMS(f)*sqrt(numel(V))
The more youi increases the density, the more you get big value of std, it increases line sqrt of the number of points.
Han
Han 2022 年 8 月 10 日
編集済み: Han 2022 年 8 月 12 日
@Bruno Luong @Walter Roberson @KSSV Code and data updated. can you watch it again?
Bjorn Gustavsson
Bjorn Gustavsson 2022 年 8 月 10 日
@Han: You need to look at @Jan's example and have a think about what that example shows.
Jan
Jan 2022 年 8 月 10 日
編集済み: Jan 2022 年 8 月 13 日
@Han: Just a note, you can simplify:
gd_int = griddata(Nx7,Ny7,Nz7,xq_int,yq_int);
gd_int1 = gd_int*(10^5);
gd_int2 = gd_int1;
gd_int3 = round(gd_int2);
gridsize = 512;
for i = 1:gridsize
for j = 1:gridsize
if isnan(gd_int3(i,j))
gd_int4(i,j) = -32767;
else
gd_int4(i,j) = gd_int3(i,j);
end
end
end
M = gd_int4;
for i = 1:gridsize
for j = 1:gridsize
if isnan(gd_int3(i,j))
gd5(i,j) = 0;
else
gd5(i,j) = gd_int3(i,j);
end
end
end
AB2 = nonzeros(gd5);
for i = 1:gridsize
for j = 1:gridsize
if isnan(gd_int(i,j))
gd6(i,j) = 0;
else
gd6(i,j) = gd_int(i,j);
end
end
end
AB = nonzeros(gd6);
to:
A = griddata(Nx7, Ny7, Nz7, xq_int, yq_int);
B = round(A * 1e5);
M = fillmissing(B, 'constant', -32767);
AB2 = nonzeros(fillmissing(B, 'constant', 0));
AB = nonzeros(fillmissing(A, 'constant', 0));

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

回答 (1 件)

Jan
Jan 2022 年 8 月 9 日
編集済み: Jan 2022 年 8 月 9 日

0 投票

Of course increasing the number of points by an interpolation reduces the standard deviation:
std([1,100])
ans = 70.0036
std(interp1([1, 2], [1, 100], linspace(1, 2, 100)))
ans = 29.0115
std(1:100) % Which is the same except for rounding effects
ans = 29.0115

1 件のコメント

Han
Han 2022 年 8 月 10 日
Code and data updated. can you watch it again?

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

質問済み:

Han
2022 年 8 月 9 日

編集済み:

Jan
2022 年 8 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by