![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/176973/image.jpeg)
How can I extract a profile from a surface?
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello everybody, I would like to extract a profile from a surface. My initial matrix is composed by a matrix (18011*3) of Longitude, Latitude and Depth values. Specifically, I'd like a function that in input takes the position of start (A) and end of my profile (B) (xa,ya,xb,yb) and in output return the position of the corresponding z in A and B {e.g. [A,B] = myfunc(xa,ya,xb,yb)}. I am new in matlab and now very desperated ... Someone can help me, please?
Leonardo
0 commentaires
Réponses (2)
Iddo Weiner
le 1 Fév 2017
Hi Leonardo, I hope I understood your question properly... Here's my suggestion (I worked with small made-up data):
data = rand([5,5,5]);
xA = 2; xB = 4; yA = 5; yB = 5;
zA = data(xA,yA,:); zB = data(xB,yB,:);
% initiate new arrays and use a loop to lower the dimensions:
low_zA = nan(length(zA),1);
for i = 1:(length(low_zA))
low_zA(i) = zA(1,1,i);
end
low_zB = nan(length(zB),1);
for i = 1:(length(low_zB))
low_zB(i) = zB(1,1,i);
end
% now if you want to draw each of the profiles:
plot(low_zA,'r-p')
hold on
plot(low_zB,'k--*')
ylabel('Z axis value')
legend('zA','zB')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/176973/image.jpeg)
Notice that I have some code duplication here. I'd generalize this example into a function before starting to work with it.
Hope this helps,
Iddo
Walter Roberson
le 1 Fév 2017
https://www.mathworks.com/help/images/ref/improfile.html has it already built in (Image Processing Toolbox)
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!