surf creates two surfaces, one matches the data points but the other incorrectly connects opposite edges directly

1 view (last 30 days)
surf creates two surfaces, one matches the data points but the other incorrectly connects opposite edges together. How to generate a single surface only connecting adjacent points?
Code:
fidDoubleCrossover = fopen('doublecrossover.txt');
% fill the array in column order:
DoubleCrossover = fscanf(fidDoubleCrossover, '%d', [3 inf]);
DoubleCrossover = DoubleCrossover';
% close the file
fclose(fidDoubleCrossover);
x = DoubleCrossover(:,1);
y = DoubleCrossover(:,2);
z = DoubleCrossover(:,3);
[X,Y] = meshgrid(x,y);
Z = griddata(x,y,z, X, Y,'natural');
figure('color',[1,1,1]);
h = surf(X,Y,Z,'FaceAlpha',0.1);
hold on
stem3(X,Y,Z,'.','MarkerSize',15)
Data in file:
5 5 1195
15 5 2165
25 5 1159
35 5 1186
45 5 1474
5 15 1059
15 15 1001
25 15 946
35 15 1003
45 15 949
5 25 1203
15 25 992
25 25 927
35 25 925
45 25 923
5 35 1192
15 35 1026
25 35 946
35 35 943
45 35 927
5 45 1066
15 45 967
25 45 936
35 45 934
45 45 925

Accepted Answer

darova
darova on 19 Jan 2020
Try
x1 = linspace(min(x),max(x),5);
y1 = linspace(min(y),max(y),5);
[X,Y] = meshgrid(x1,y1);
Please use special buttons
CODE_INSER.PNG

More Answers (0)

Tags

Products

Community Treasure Hunt

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

Start Hunting!