声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1123|回复: 1

[综合讨论] 新手求助~哪位大虾帮忙调试一下这个程序,非常感谢!

[复制链接]
发表于 2008-5-20 12:46 | 显示全部楼层 |阅读模式

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

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

x
这时我同学给我做参考的,但是我运行老提示出错,哪位大虾帮忙调试一下,不胜感谢!



%programshijin.m
x=-2:0.1:2;
b=1;
c=1;
figure(1)
subplot(2,1,1);
y=-b.*x.^2/2+c.*x.^4/4;
plot(x,y);
subplot(2,1,2);
b=3:0.1:7;
c=2:0.1:6;
h=moviein(40);
fori=1:40;
y=-b(i).*x.^2/2+c(i).*x.^4/4;
plot(x,y);
h(:,i)=getframe;
end
title('势函数随b,c的变化情况')
subplot(2,1,1)
title('无信号及噪声输入时系统的势函数')
xlabel('x');
ylabel('U(x)');
subplot(2,1,2)
xlabel('x');
ylabel('U(x)');
movie(h,1);
figure(2)
b=1;
c=1;
w=pi;
z=0;
subplot(2,1,1)
A=2;
m=moviein(20);
[t,yy]=ode23('xinhao1',[0:0.1:10],[1,b-c+A],[],b,z,c,A,w);
n=length(t);
fori=1:fix(n/2)
axis([-22-510]);
y=-b.*x.^2/2+c.*x.^4/4-A.*x.*sin(w*t(i));
plot(x,y);
holdon
uu=yy(i,2)*yy(i,2)/2-b.*yy(i,1).^2/2+c.*yy(i,1).^4/4-A.*yy(i,1).*sin(w*t(i));
uu=-b.*yy(i,1).^2/2+c.*yy(i,1).^4/4-A.*yy(i,1).*sin(w*t(i));
plot(yy(i,1),uu,'.r','markersize',10)
holdoff
m(:,i)=getframe;
end
title('加入周期信号较小,不足以翻转')
xlabel('x');
ylabel('U(x)');
v=moviein(20);
subplot(2,1,2)
A=3;
[t,yy]=ode23('xinhao1',[0:0.1:10],[1,b-c+A],[],b,z,c,A,w);
n=length(t);
fori=1:fix(n/2)
y=-b.*x.^2/2+c.*x.^4/4-A.*x.*sin(w*t(i));
plot(x,y);
holdon
uu=yy(i,2)*yy(i,2)/2-b.*yy(i,1).^2/2+c.*yy(i,1).^4/4-A.*yy(i,1).*sin(w*t(i));
uu=-b.*yy(i,1).^2/2+c.*yy(i,1).^4/4-A.*yy(i,1).*sin(w*t(i));
plot(yy(i,1),uu,'.r','markersize',10)
holdoff
v(:,i)=getframe;
end
title('加入周期调制信号较大,可以翻转')
holdon
xlabel('x');
ylabel('U(x)');
axis([-22-510])
holdon
movie(v)
t=0:0.1:10;
n=length(t);
figure(3)
A=2;
b=1;
m=moviein(20);
fori=1:fix(n/2)
r=2*rand(1)
y=-b.*x.^2/2+c.*x.^4/4-A.*x.*sin(w*t(i))-r.*x;
plot(x,y);
holdon
[t,s,r]=oula('f',0,5,rand(1),0.1,r);
u=-b.*s(i).^2/2+c.*s(i).^4/4-A.*s.*sin(w*t(i))-r*s(i);
plot(s(i),u(i),'.r','markersize',10);
holdoff
m(:,i)=getframe;
end
title('加入随机噪声的情况,参数选取同figure(2)中未翻转时');
xlabel('x');
ylabel('U(x)');
movie(m,1)
figure(4)
x=-2:0.1:2;
w=50*pi;
b=1;
c=1
A=1;
t=0:0.01:10;
n=length(t);
subplot(2,1,1);
fori=1:n
y(i)=b.*x(1)-c.*x(1).^3+A.*cos(w*t(i))+0.5*rand(1);
end
plot(t,y)
title('信号的波形图');
xlabel('t');
ylabel('U(x)');
subplot(2,1,2)
z=fft(y);
z(1)=[];
n=length(z);
p=10^(-5).*abs(z(1:n/2)).^2
m=1/2;
f=100*(1:n/2)/(n/2)*m;
plot(f,p)
title('信号的频谱图,w=50*pi,f=25');

[ 本帖最后由 skyfans 于 2008-5-20 15:26 编辑 ]
回复
分享到:

使用道具 举报

 楼主| 发表于 2008-5-20 15:28 | 显示全部楼层
Subscript indices must either be real positive integers or logicals
中文解释:下标索引必须是正整数类型或者逻辑类型
出错原因:在访问矩阵(包括向量、二维矩阵、多维数组,下同)的过程中,下标索引要么从 0 开始,要么出现了负数。注:matlab 的语法规定矩阵的索引从 1 开始,这与 C 等编程语言的习惯不一样。
解决办法:自己调试一下程序,把下标为 0 或者负数的地方修正。


我按照上述的方法调试了,但是能改的都改了,还是没找到错误的地方,SOS!!!
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

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

GMT+8, 2024-6-1 08:20 , Processed in 0.052878 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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