Borrar filtros
Borrar filtros

How do I get directional profile of 2D functions ?

3 visualizaciones (últimos 30 días)
Bastien Rouzé
Bastien Rouzé el 31 de Jul. de 2017
Comentada: Star Strider el 31 de Jul. de 2017
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

Respuesta aceptada

Star Strider
Star Strider el 31 de Jul. de 2017
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 comentarios
Bastien Rouzé
Bastien Rouzé el 31 de Jul. de 2017
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 el 31 de Jul. de 2017
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.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by