How to change and ignore some values of depth in meshgrid/contour3 command?
Mostrar comentarios más antiguos
Hi, I've been working on the first part of the following data, where I tried to extract depth data from a txt file, in order to get a matrix organised such as X, Y, Z , where X, Y represent the grid and Z represents the bathymetry data. The code works, although there are some errors related to index exceeding matrix dimensions. The second part was taken from this previous post: https://it.mathworks.com/matlabcentral/answers/445313-bathymetric-data-into-a-surface-plot
clear all
close all
%%%%%%%%%%%% FIRST PART
filename = 'DepKilkeeGROSSA1.dep'; % file with the depth data, it's the txt attached
delimiterIn = ' '; % read the file, and
headerlinesIn = 0; %
A = importdata(filename,delimiterIn,headerlinesIn); %get matrix A with all the data
[horiz,vert]=size(A); %dimension of the matrix A
Matrix=zeros(horiz,3); %target matrix, in a form such as X, Y, Z
%indices to read the data file and assign the values to the matrix
m=7; %number of lines that contain one block of coordinates
n=vert;
a=1;
b=1;
cont=1;
c=0;
row=1;
column=1;
line=1;
while cont<=horiz
a=1;
for i=row:m
for j=column:n
c=A(i,j); %assign values of matrix A to variable c
Matrix(line,1)= a; %assign values to Matrix: coordinates
Matrix(line,2)= b; % 1 1 "value of A(i,j)
Matrix(line,3)= c; % 2 1 "value of A(i,j+1)
a=a+1; % 3 1 "value of A(i,j+2)
line=line+1;
end
end
row=m+1;
%n=n+12;
m=m+7;
b=b+1;
cont=cont+1;
end
%%
%%%%%%%%%%%%%%%%%SECOND PART, Bathymetry, Plot
Lon = Matrix(:,1);
Lat = Matrix(:,2);
Dep = Matrix(:,3);
%
[dimR,dimC]=size(Matrix);
for ind=1:dimR
if(Matrix(ind,3))==-999;
Matrix(ind,3)=NaN;
end
end
%
figure
plot3(Lon, Lat, Dep, '.')
grid on
view(35,25)
title('Exploratory Plot')
xLon = linspace(min(Lon), max(Lon), 1E+3);
yLat = linspace(min(Lat), max(Lat), 1E+3);
[X,Y] = meshgrid(xLon, yLat);
zDep = griddata(Lon, Lat, Dep, X, Y);
figure
mesh(X, Y, zDep)
grid on
view(35,25)
title('Mesh Plot')
figure
mesh(X, Y, zDep)
hold on
contour3(X, Y, zDep, 50, 'k', 'LineWidth',2)
hold off
grid on
view(35,25)
title('Mesh Plot With Contours')
I have two problems about it: 1) bathymetry data are positive, while lands are considered negative in the original file. Is there a way to represent reversed values, where water depth becomes negative and land becomes positive? 2) In the orginal file there are some "-999" values, that I would like to cut out; in general, I would like to represent the contour plot with maximum and minimum values of depth on the vertical axis, without the "-999" values. Is there a way to do it?
Thanks to anyone could help, much appreciated!
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Polar Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!