Borrar filtros
Borrar filtros

How do I make a contour?

2 visualizaciones (últimos 30 días)
민제 강
민제 강 el 16 de Jun. de 2021
Comentada: John D'Errico el 21 de Feb. de 2024
data = readtable('kriging_branin_20');
krin = readtable('LHS_branin_20.xlsx');
ux1 = unique(data.x1);
nx1 = length(ux1);
X1 = reshape(data.x1, [], nx1);
X2 = reshape(data.x2, [], nx1);
Y = reshape(data.Y, [], nx1);
K = reshape(data.Kriging, [], nx1);
kerr = Y - K;
figure
contourf(X1, X2, abs(kerr), 20)
hold on
scatter3(krin.x1, krin.x2, krin.LHS, 50, 'r', 'filled')
hold off
colormap turbo
xlabel('x1')
ylabel('x2')
title('Sample(n=20)')
colorbar
caxis([0 1])
It is well made in the branin file. However, it is not well made in the rosenbrock file.
Please modify my code. And I want to make contour softer like a Sample_contour picture.
Thank you.
sample_contour
  2 comentarios
SALAH ALRABEEI
SALAH ALRABEEI el 16 de Jun. de 2021
It depends on your data, but you can play with the intensity level instead of 20 ( increase/decrease).
민제 강
민제 강 el 16 de Jun. de 2021
I've tried, but it still doesn't work.

Iniciar sesión para comentar.

Respuestas (1)

Shivam Lahoti
Shivam Lahoti el 21 de Feb. de 2024
Hi 민제 ,
To achieve smoother contours in your plot, you can interpolate the kerr onto a finer grid using interp2. Create a denser mesh with meshgrid and use spline interpolation to obtain the new kerr values. Then, plot the interpolated data with contourf for a smoother appearance. However, be cautious: interpolation can introduce artifacts that may not reflect the actual data distribution.
Kindly refer to the following MATLAB answers, they discuss some other solutions in similar context:
I hope it was helpful.
Regards,
Shivam.
  1 comentario
John D'Errico
John D'Errico el 21 de Feb. de 2024
This is a well-intentioned answer to this moderately old question, that sadly, never got a timely answer. However, I think your answer misunderstands some facts.
For each surface, the user has provided two sets of points. First is a 20 point scattered set of data. And then they already used kriging to generate a second set of points that lie on a grid. Kriging is itself an interpolation method, one that can be used for cattered data interpolation. As well, kriging can be used to extrapolate scattered data (though it will do so poorly, as will any such method when used for extrapolation.) So if they wanted a finer grid, they could simply have used kriging on the original set to interpolate onto a finer grid!
There is no need to use an interpolation tool to interpolate that grid. In fact, that itself is an arguably bad idea, since interp2 will itself introduce interpolation artifacts. You don't want to interpolate already interpolated data if you have a choice. Just do a finer interpolation in the first place.
As well, you cannot use interp2 to interpolate scattered data (though I think you recognize that.) It would only apply to the already interpolated kriging data.
Anyway, the problem that seems to be vexing @민제 강 is that the Rosenbrock data was not originally interpolated using kriging over the entire domain of the scattered sample. As you can see, there is some white space on the edge of that plot. And interp2 will extrapolate at best only poorly anyway. Since there were only 2 data points outside of the domain, asking interp2 to intelligently extrapolate there is far beyond its capabilities. It would surely introduce major artifacts there.

Iniciar sesión para comentar.

Categorías

Más información sobre Orange en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by