如何在Matlab中编写此函数?我得到矩阵错误 [英] How Can I Write This Function In Matlab? I Got Matrix Eror

查看:84
本文介绍了如何在Matlab中编写此函数?我得到矩阵错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在matlab中编写此函数?我得到矩阵错误

How can i write this function in matlab? i got matrix eror

n=1:100; 
k=0.5; 
x[n]=sin((3*pi*n)/20); 
y(n)=x(n./k);
scale (x,k);

推荐答案

1  n=1:100;
2  k=0.5;
3  x[n]=sin((3*pi*n)/20);
4  y(n)=x(n./k);
5  scale (x,k);





I把行号作为参考...

第一行很好,创建一个从1到100的向量。

第二行定义一个标量值k。

第三行,这是无效的,你不能使用向量作为索引。你可以循环或只是删除索引引用。



I put line numbers for reference...
Line one is fine, creates a vector from 1 to 100.
Line two defines a scalar value k.
Line three, this is invalid, you can't use a vector as an index. You can either loop or simply remove the index reference.

x=sin((3*pi*n)/20); %valid



第四行,同样的事情......因为你使用向量作为索引而无效。当一个是向量而另一个是标量时,你也不需要 ./ 运算符,它没有意义。此外,此n / k将为某些n值提供非整数值,这不是有效索引。


Line four, same thing... invalid because you're using a vector as an index. You also don't need the ./ operator when one is a vector and the other is a scalar, it doesn't make sense. Also, this n/k will give you non-integer values for some values of n, which is not a valid index.


这篇关于如何在Matlab中编写此函数?我得到矩阵错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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