MATLAB: How to separate each graph in contour plot

contourMATLABplot

1. I load a data.
2. And i draw a graph in contour plot to find diagonal patterns of data.
I want to separate each pattern and show them in each figure.
but i don't know how to set range in contour plot.
x = enter a value: % I would enter a value of x.
if x>0 & x<269 %because 1st pattern's range of x is 0~268.
figure(1)
contour(?) % i don't know how to write a code in here.
end
if x>268 & x<420 % 2nd pattern's range of x is 269~419.
figure(2)
contour(?)
end
.
.
.
To do make a code like this how should i do?
could you help me?

Best Answer

See if this gets you started:
D = load('Norman Breedman data.mat');
Z = D.z;
x = 1:size(Z,2);
y = 1:size(Z,1);
[X,Y] = meshgrid(x,y); % Create Independent Coordoinates
figure(1)
hm = meshc(X,Y,Z); % View Data
grid on
rotate(hm, [0 0 1], +30) % Rotate To ‘Straighten’ Contours
rotsurf = findobj(hm, 'Type', 'Surface'); % Get ‘Surface’ Object
figure(2)
meshc(rotsurf.XData, rotsurf.YData, rotsurf.ZData) % Check Rotated Data
grid on
xlabel('X Axis \rightarrow')
ylabel('\leftarrow Y Axis')
Xr = rotsurf.XData;
Yr = rotsurf.YData;
Zr = rotsurf.ZData;
figure(3)
hc = contour(Xr,Yr,Zr, [-1; -1]*0.3); % Plot Rotated Data
grid
colorbar
cntrs = find(hc(1,:) == -0.3, 22, 'first'); % Contours At Designated Level (Here -0.3)
figure(4)
subplot(1,2,1)
plot(hc(1,cntrs(1)+1:cntrs(2)-1), hc(2,cntrs(1)+1:cntrs(2)-1)) % First Contour
axis equal
grid
subplot(1,2,2)
plot(hc(1,cntrs(2)+1:cntrs(3)-1), hc(2,cntrs(2)+1:cntrs(3)-1)) % Second Contour
axis equal
grid
figure(5)
for k1 = 1:22-1
subplot(2,11,k1)
plot(hc(1,cntrs(k1)+1:cntrs(k1+1)-1), hc(2,cntrs(k1)+1:cntrs(k1+1)-1))
axis equal
grid
end
The code first plots the data (so I can see what the problem is), the rotates it so that all the ‘x’ values are unique to each contour. It then plots the contours of the rotated data (in figure(3)), and returns the x- and y-coordinates in each contour in ‘hc’. (See the documentation for contour for details.) The first two contours are plotted in figure(4) and all in figure(5). You will probably have to tweak the code to get what you want, since the find call seems to have returned some spurious indices. I will let you sort that.