フィルターのクリア

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 Center および File ExchangeGrid 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