声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1052|回复: 3

[编程技巧] 下标出现了0怎么处理?

[复制链接]
发表于 2007-6-14 09:50 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
具体是这样的
clear all
close all
sample_N=16;
n=1:sample_N;
x(n)=sin(2*pi*n/sample_N);
r(n)=randn(1,sample_N)
u(n)=x(n)+r(n)
figure(1);
plot(u(n));
pr=0.01;
d(n)=2*cos(2*pi*n/sample_N);
h1=mean(u(n)*u(n-1));
g1=mean(d(n)*u(n-1));

错误提示是这个:??? Subscript indices must either be real positive integers or logicals.
Error in ==> lms at 12
h1=mean(u(n)*u(n-1))

求均方的公式出现了u(0)这种不存在的情况

如果改成
u(n+1)u(n)的话矩阵又溢出了,
谁帮下忙,谢谢

[ 本帖最后由 eight 于 2007-6-14 10:39 编辑 ]
回复
分享到:

使用道具 举报

发表于 2007-6-14 10:13 | 显示全部楼层
clear all
close all
sample_N=16;
n=1:sample_N;
x=sin(2*pi*n/sample_N);
r=randn(1,sample_N);
u=x(n)+r(n);

figure(1);
plot(u);
pr=0.01;
d=2*cos(2*pi*n/sample_N);
for n=2:sample_N
    h1=mean(u(n)*u(n-1));
    g1=mean(d(n)*u(n-1));
end

评分

1

查看全部评分

发表于 2007-6-14 10:20 | 显示全部楼层
clear all
sample_N=16;
n=1:sample_N;
x(n)=sin(2*pi*n/sample_N);
r(n)=randn(1,sample_N);
u(n)=x(n)+r(n);
figure(1);
plot(u(n));
pr=0.01;
d(n)=2*cos(2*pi*n/sample_N);
for i=2:length(u)
    h1(i-1)=u(i)*u(i-1);
    g1(i-1)=d(i)*u(i-1);
end
h=mean(h1)
g=mean(g1)
慢了,还不简练,功力不够啊

[ 本帖最后由 花如月 于 2007-6-14 10:23 编辑 ]

评分

1

查看全部评分

发表于 2007-6-14 10:44 | 显示全部楼层
原帖由 清水小鱼 于 2007-6-14 09:50 发表
具体是这样的
clear all
close all
sample_N=16;
n=1:sample_N;
x(n)=sin(2*pi*n/sample_N);
r(n)=randn(1,sample_N)
u(n)=x(n)+r(n)
figure(1);
plot(u(n));
pr=0.01;
d(n)=2*cos(2*pi*n/sample_N) ...


看这个帖子:常见的程序出错问题整理

ps:看在有两个回帖的份上这个帖子就不删除了,否则一定不会手软。下次发贴前先自己动手
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-21 00:48 , Processed in 0.097363 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表