还是MATLAB问题

来源:百度知道 编辑:UC知道 时间:2024/06/30 15:25:45
C=0.256e-3;
R=zeros(1,300);
syms x n
K=0.01*C/n^2*cos(2*pi*n*x);
P=int(K,n,0.01,3);
P
i=0;
for x=0:0.01:3
R(i)=P;
i=i+1;
end
请大家帮我看看,为什么运行出来这样?
??? Subscript indices must either be real positive integers or logicals.

Error in ==> A1 at 17
R(i)=P;
我期望的结果是一维的行向量或一维的列向量,也就是确定的值了

恩 你的问题是,Matlab中数组的第一个下标是1不是0,我将代码改进下,去除了循环语句,使速度更快
%by dynamic
%see also http://www.matlabsky.com
%contact me matlabsky@gmail.com
%2009.2.
%

C=0.256e-3;
syms x n
K=0.01*C/n^2*cos(2*pi*n*x);
P=int(K,n,0.01,3);
Px=inline(P);
x=0:0.01:3;
R=Px(x);

修改成:
C=0.256e-3;
R=[];
syms x n
K=0.01*C/n^2*cos(2*pi*n*x);
P=int(K,n,0.01,3);
P
i=0;
for x=0:0.01:3
R=[R,P];
i=i+1;
end

matlab数组下标不能从0开始
你的程序里存在R(0)