After using griddata, standard deviation is changed.
Show older comments
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 Comments
KSSV
on 9 Aug 2022
Show us your data and code.
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)
std(Vq(:), 'omitnan')
Bruno Luong
on 9 Aug 2022
Edited: Bruno Luong
on 9 Aug 2022
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.
Bjorn Gustavsson
on 10 Aug 2022
@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));
Answers (1)
Of course increasing the number of points by an interpolation reduces the standard deviation:
std([1,100])
std(interp1([1, 2], [1, 100], linspace(1, 2, 100)))
std(1:100) % Which is the same except for rounding effects
Categories
Find more on Design of Experiments (DOE) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!