MATLAB中的绘图功能 [英] Plotting function in MATLAB

查看:93
本文介绍了MATLAB中的绘图功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Matlab中绘制以下函数时遇到问题:

I am having a problem plotting the following function in Matlab:

x = 10*((sin(pi*f*0.1))/(pi*f*0.1))^2;

我正在使用以下代码:

f = -50:0.1:50;
x = 10*((sin(pi*f*0.1))/(pi*f*0.1))^2;
plot (f,x);

我可以使用我在Google上找到的图形工具来绘制函数,但MATLAB只是给我一个空白图.轴也不对应我应该得到的.

I can plot the function using a graph tool I found on google but MATLAB is just giving me a blank plot. The axis don't correspond to what I should be getting either.

有人知道为什么这张图没有显示出来吗?

Does anyone know why this graph doesn't appear as it should?

推荐答案

您需要使用 (/)尝试求解线性系统.同样,您需要使用逐元素 power(.^)而不是矩阵功效,是 mpower(^).

You need to use element-wise division (./) rather than mrdivide (/) which attempts to solve a linear system. Similarly, you need to use the element-wise power (.^) rather than the matrix power, mpower (^).

x = 10 * ((sin(pi * f * 0.1)) ./ (pi * f * 0.1)).^2;

运算符中的.是微妙的,在处理标量时不是必需的.但是,如果要在处理多维数组时采用按元素的行为,则必须使用它.

The . in the operator is subtle and not necessary when working with scalars; however you must use it if you want element-wise behavior when working with multi-dimensional arrays.

为了与通用约定保持一致,我建议切换fx,以便您具有功能f(x)

Also to be consistent with common conventions, I'd recommend switching f and x so you have a function f(x)

x = -50:0.1:50;
f = 10 * ((sin(pi * x * 0.1)) ./ (pi * x * 0.1)).^2;
plot(x, f)

这篇关于MATLAB中的绘图功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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