Find minimum value out of a 3D contour plot

14 views (last 30 days)
Hi!
I plotted a contour graph and I want to find its minimum value i.e. without using a thinner mesh. However, I do not know what is the best way to get its minimum value as much accurate as possible. I do not know if an interpolation or fit is the best way to do that or if exists a better option. What I exactly want are the values of a and c for which M is minimum.
a=[SUMMARY(1,1) SUMMARY(10,1) SUMMARY(19,1) SUMMARY(28,1) SUMMARY(37,1) SUMMARY(46,1) SUMMARY(55,1) SUMMARY(64,1) SUMMARY(73,1)];
c=[SUMMARY(1,2) SUMMARY(2,2) SUMMARY(3,2) SUMMARY(4,2) SUMMARY(5,2) SUMMARY(6,2) SUMMARY(7,2) SUMMARY(8,2) SUMMARY(9,2)];
[x,y]=meshgrid(a,c);
M=zeros(9,9);
for i=1:length(SUMMARY)
if i<=9
M(1,i)=SUMMARY(i,5);
elseif i>9 && i<=18
M(2,i-9)=SUMMARY(i,5);
elseif i>18 && i<=27
M(3,i-18)=SUMMARY(i,5);
elseif i>27 && i<=36
M(4,i-27)=SUMMARY(i,5);
elseif i>36 && i<=45
M(5,i-36)=SUMMARY(i,5);
elseif i>45 && i<=54
M(6,i-45)=SUMMARY(i,5);
elseif i>54 && i<=63
M(7,i-54)=SUMMARY(i,5);
elseif i>63 && i<=72
M(8,i-63)=SUMMARY(i,5);
elseif i>72 && i<=81
M(9,i-72)=SUMMARY(i,5);
end
end
contourf(x,y,M)
xlabel('a (\AA)','Interpreter','Latex','FontSize',14,'FontWeight','bold');
ylabel('c (\AA)','Interpreter','Latex','FontSize',14,'FontWeight','bold');
Regard
  2 Comments
Adam Danz
Adam Danz on 2 Jan 2020
Attaching a mat file with experimental_data_1 and experimental_data_2 data would give us a full picture of what's going on in that contour plot.
Miguel Cardoso
Miguel Cardoso on 2 Jan 2020
I added the full code and attached my experimental data.

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 2 Jan 2020
Edited: Adam Danz on 2 Jan 2020
Below is a simplification of your code.
load('SUMMARY.mat')
a = SUMMARY([1 10 19 28 37 46 55 64 73],1).'; % Simpler
c = SUMMARY(1:9,2).'; % Simpler
[x,y]=meshgrid(a,c);
M = reshape(SUMMARY(:,5),size(x)).'; % This produces the same thing as your for-loop.
contourf(x,y,M);
xlabel('a (\AA)','Interpreter','Latex','FontSize',14,'FontWeight','bold');
ylabel('c (\AA)','Interpreter','Latex','FontSize',14,'FontWeight','bold');
axis equal; % added
colorbar % added
To find the (x,y) coordinate of the minimum z-value within your data,
[~, minIdx] = min(M(:));
[row,col] = ind2sub(size(M),minIdx);
xMin = x(row,col);
yMin = y(row,col);
% Plot this coordinate
hold on
plot(xMin, yMin, 'rx')
[Update] To interpolate and find minimum, (plot shown below)
% same as above
load('SUMMARY.mat')
a = SUMMARY([1 10 19 28 37 46 55 64 73],1).';
c = SUMMARY(1:9,2).';
[x,y]=meshgrid(a,c);
M = reshape(SUMMARY(:,5),size(x)).';
contourf(x,y,M,20);
% interpolate using cubic convolution (1000 points)
[xq,yq]=meshgrid(linspace(min(a),max(a),1000), linspace(min(c),max(c),1000));
Mq = interp2(x,y,M,xq,yq,'cubic');
% Same as above but acting on interpolated data
% Find min
[~, minIdx] = min(Mq(:));
[row,col] = ind2sub(size(Mq),minIdx);
xMin = xq(row,col);
yMin = yq(row,col);
% Mark min on plot
hold on
plot(xMin, yMin, 'rx', 'MarkerSize', 12)
200102 141811-Figure 1.png
  4 Comments
Miguel Cardoso
Miguel Cardoso on 2 Jan 2020
Edited: Miguel Cardoso on 2 Jan 2020
It is possible to interpolate this region and get a point outside of my dataset? I do not know if I should use an interpolation or a fit.
Adam Danz
Adam Danz on 2 Jan 2020
Yes! I've updated my answer to show how.

Sign in to comment.

More Answers (0)

Categories

Find more on Contour Plots 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!