![untitled.bmp](https://www.mathworks.com/matlabcentral/answers/uploaded_files/250712/untitled.bmp)
How to make section distance of temperature
조회 수: 2 (최근 30일)
이전 댓글 표시
I would like to make section distance from depth, section distance, and temperature data with bottom topography shown (as the picture shown). Here is my excel data, and I have tried to programing on syntax as follow. But it's not working especially for the boundary loop. Is there any idea for this? I utilize Matlab 2019a
clc
clear
data=xlsread('ctd_data.xlsx');
x=data(:,5); %first colum in excel file, as distance
y=data(:,3)*-1;%second colum in excel file, as depth
c=data(:,4); %c is the concentration of Temperature
figure(1)
scatter(x,y,30,c,'filled')
colorbar
axis tight; hold on
shading interp
ylabel('Depth (m)');
title('Temperature distribution');
figure(2)
[xg,yg] = meshgrid(min(x):0.1:max(x),min(y):0.1:max(y)); %make a grid to contain x,y
f = scatteredInterpolant(x,y,c,'linear'); %assign c values to x y
vg = f(xg,yg);% assign c values to finer pixel xg yg
for i=1:(length(x)-1)% 1 to end of the distance
if x(i+1)~=x(i)
j=i+1;
bx(j)=x(i);
by(j)=y(i);
end
end
bx(j+1)=x(length(x));
by(j+1)=y(length(y));
bx(j+2)=x(length(x));
by(j+2)=0;
b=boundary(x,y,1);
inmask = inpolygon(xg(:),yg(:), bx , by );%define which pixel exist in the polygon
vg(~inmask) = nan; %NAN values for the pixel not in the polygon
h = pcolor(xg,yg,vg); %ploting in 2D of vg by color
h.EdgeColor = 'none'; %to get rid off the edge line
h.FaceColor = 'interp';
colorbar
xlabel('Distance (km)');
ylabel('Depth (m)');
Desired picture :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/250639/image.jpeg)
result syntax :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/250640/image.jpeg)
댓글 수: 0
채택된 답변
jonas
2019년 11월 27일
편집: jonas
2019년 11월 27일
Simply skipping the loop and changing the line
inmask = inpolygon(xg(:),yg(:), bx , by );%define which pixel exist in the polygon
to
inmask = inpolygon(xg(:),yg(:), x(b) , y(b) );%define which pixel exist in the polygon
Gives more or less the desired result. The boundary() function does not seem to capture all the corners though.
Here is a better method which works because you are working with grouped data, i.e. several measurements on the exact same depth.
data=xlsread('ctd_data.xlsx');
x=data(:,5); %first colum in excel file, as distance
y=data(:,3)*-1;%second colum in excel file, as depth
c=data(:,4); %c is the concentration of Temperature
figure(1)
scatter(x,y,30,c,'filled')
colorbar
axis tight; hold on
shading interp
ylabel('Depth (m)');
title('Temperature distribution');
figure(2)
[xg,yg] = meshgrid(min(x):0.1:max(x),min(y):0.1:max(y)); %make a grid to contain x,y
f = scatteredInterpolant(x,y,c,'linear'); %assign c values to x y
vg = f(xg,yg);% assign c values to finer pixel xg yg
%find boundary
[g,xd] = findgroups(x)
yd_top = splitapply(@min,y,g)
yd_bot = splitapply(@max,y,g)
yd = [yd_top;flip(yd_bot)];
xd = [xd;flip(xd)]
inmask = inpolygon(xg(:),yg(:), xd , yd );%define which pixel exist in the polygon
vg(~inmask) = nan; %NAN values for the pixel not in the polygon
h = pcolor(xg,yg,vg); %ploting in 2D of vg by color
h.EdgeColor = 'none'; %to get rid off the edge line
h.FaceColor = 'interp';
colorbar
xlabel('Distance (km)');
ylabel('Depth (m)');
![untitled.bmp](https://www.mathworks.com/matlabcentral/answers/uploaded_files/250712/untitled.bmp)
cheers!
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!