如何在具有亮度的MATLAB中用相位信息绘制复杂函数 [英] How Can I Plot a Complex Function With Phase Information in MATLAB With Brightness

查看:152
本文介绍了如何在具有亮度的MATLAB中用相位信息绘制复杂函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在MATLAB中绘制一个带有相位信息的复杂函数.为此,我绘制了一个冲浪图,其中x,y表示实数和虚数,高度表示幅度和颜色,具体取决于相位,如下面的log(x)示例所示:

I need to plot a complex function with phase information in MATLAB. To do this I have ploted a surf plot with x,y representing real and imaginary, the height representing the magnitude and colour depending on the phase, as shown below for the example of log(x):

xmin=-5;
xmax=5;
dx=0.1;
xReal = xmin:dx:xmax;
xImaginary = xmin:dx:xmax;
[x,y] = meshgrid(xReal, xImaginary);
s = x + 1i*y;
z=log(s);
magnitude = abs(z1);
Phase = angle(z);
figure;
h(1) = surf(x,y,magnitude,Phase,'EdgeColor','none');
xlabel('Real');
ylabel('imaginary');
legend('Magnitude');

这有效,但是很难看到情节的特征.相反,我希望将函数的高度绘制为亮度.有办法吗?

This works, however features of the plot are very difficult to see. I'd desire instead to plot the height of the function as brightness. Is there a way to do this?

推荐答案

一种方法是将magnitude值的倒数用作AlphaData,这将导致更高的值更轻(更透明)后面带有白色轴),而值越低则越暗(更不透明).

One way to do this would be to use the inverse of the magnitude value as the AlphaData which would cause higher values to be lighter (more transparent with a white axes behind it) and lower values to be darker (more opaque).

h = surf(x, y, zeros(size(magnitude)), 'EdgeColor', 'none');
set(h, 'FaceColor', 'flat', 'CData', Phase, 'FaceAlpha', 'flat', 'AlphaData', -magnitude);
view(2);

如果您还有其他图对象并且不能依赖透明度,则可以使用白色手动抖动颜色.

If you have other plot objects and can't rely on transparency, you can instead manually dither the colors with white.

% Determine the RGB color using the parula colormap
rgb = squeeze(ind2rgb(gray2ind(mat2gray(Phase(:))), parula));

% Normalize magnitude values
beta = magnitude(:) / max(magnitude(~isinf(magnitude)));

% Based on the magnitude, pick a value between the RGB color and white
colors = bsxfun(@plus, bsxfun(@times, (1 - beta), rgb), beta)

% Now create the surface
h = surf(x, y, zeros(size(magnitude)), 'EdgeColor', 'none');
set(h, 'FaceColor', 'flat', 'CData', reshape(colors, [size(magnitude), 3]));

话虽这么说,但我不确定这是否可以使您更轻松地了解正在发生的事情.也许考虑只绘制两个图,一个用于幅值,一个用于相位.

That being said, I'm not sure if this makes it any easier to see what is happening. Maybe consider just making two plots, one for the magnitude and one for the phase.

这篇关于如何在具有亮度的MATLAB中用相位信息绘制复杂函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆