简体   繁体   English

在matlab中将复数的虚部增加一个常数

[英]Increase the imaginary part of complex number by a constant in matlab

I think this is a simple question, but I could not find an answer by googling.我认为这是一个简单的问题,但我无法通过谷歌搜索找到答案。

Let's say that I have a code like this:假设我有这样的代码:

y1=1:0.01:2;

This creates 1x101 long cell, with numbers 1, 1.01, 1.02, 1.03, 1.04, etc. Now I want to have an array of numbers which goes like 1, 1+0.01i, 1+0.02i, 1+0.03i, 1+0.04i, 1+0.05i, 1+0.06i, 1+0.07i, 1+0.08i, etc. I thought that the code 1:0.01i:2;这将创建 1x101 长单元格,其中包含数字 1、1.01、1.02、1.03、1.04 等。现在我想要一个数字数组,类似于 1、1+0.01i、1+0.02i、1+0.03i、1 +0.04i, 1+0.05i, 1+0.06i, 1+0.07i, 1+0.08i 等等。我以为代码是1:0.01i:2; will give the answer, but I am getting a warning会给出答案,但我收到警告

Warning: Colon operands must be real scalars.警告:冒号操作数必须是实数。

How to get around this?如何解决这个问题?

Thanks in advance提前致谢

As the warning message is trying to tell you, the : is meant to be used in only one dimension.正如警告消息试图告诉您的那样, :仅用于一维。 It cannot keep the real part constant and only increase the imaginary part.它不能保持实部不变,只能增加虚部。 Instead, do this:相反,请执行以下操作:

y=0:.01:1;
z=1+i*y

and z will contain the values you want. z将包含您想要的值。 Here is the relevant docs .这是相关的文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM