필터 지우기
필터 지우기

How do I get directional profile of 2D functions ?

조회 수: 3 (최근 30일)
Bastien Rouzé
Bastien Rouzé 2017년 7월 31일
댓글: Star Strider 2017년 7월 31일
Hi all,
I have a simple question : Let us define the function z = sqrt(x^2 + y^2) if r < 0.9 and r=0 else. I would like to plot the profile along a line defined by a polar angle A, see the figure within the code or enclosed :
[x,y] = meshgrid(-1:0.1:1);
z = sqrt(x.^2 + y.^2); % or it can be z = x+y or any f(x,y)...
z(sqrt(x.^2 + y.^2) > 0.9)=0; % set the area where z is defined
ax = axes;
h = imagesc(ax,-1:0.1:1,-1:0.1:1,z);
set(ax,'YDir','normal');
% The function is plotted
% Now we plot the line where I want to get the z-profile
A = 30; % in deg
x0 = cos(deg2rad(A));
y0 = sin(deg2rad(A));
hold on
plot(ax,[-x0 0 x0],[-y0 0 y0],'k-');
%end of code
I would like to get the profile along the black line direction. I have played with mesh, surf, etc.. but it does not give the result I want. But I am quite new at MATLAB...
Any help is appreciated :) B

채택된 답변

Star Strider
Star Strider 2017년 7월 31일
One approach:
v = -1:0.1:1;
xline = x0*v;
yline = y0*v;
zline = sqrt(xline.^2 + yline.^2);
zline(zline > 0.9)=0;
figure(2)
plot3(xline, yline, zline)
grid on
  댓글 수: 2
Bastien Rouzé
Bastien Rouzé 2017년 7월 31일
Yeah I agree. But in the example, I created z. Let us imagine that we have imported the z-values matrix without any knowledge on the function z = f(x,y).
Star Strider
Star Strider 2017년 7월 31일
Then let us use the interp2 (link) function to get the values of the plotted surface corresponding to ‘xline’ and ‘yline’:
v = -1:0.1:1;
xline = x0*v;
yline = y0*v;
zline = interp2(x,y,z, xline, yline, 'linear');
figure(3)
plot3(xline, yline, zline)
grid on
This is actually easier. Note that the interpolation vectors (or matrices) must be the same size. It might also be necessary to provide an extrapolation value.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Grid Lines, Tick Values, and Labels에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by