How do I fix the code of my program
古いコメントを表示
[EDIT: 20110530 23:47 CDT - reformat - WDR]
Good morning everybody,
I have an error:
This code produces an error, and here is the error message:
Subscript indices must either be real positive integers or logicals.
Error in ==> vv at 15
mean(r)=sum(y(:,i))/400;
??? Error using ==> plus
Matrix dimensions must agree.
Error in ==> vv at 7
t=5*cos(2*pi*100*(0:1/300:1)+x);
My program is:
k=-1;
for n=1:400
k=k+1;
x(k+1)=k*(-2*pi/400);
end
x=x(:)';z=ones(1,301);
t=5*cos(2*pi*100*(0:1/300:1)+x);
l=0;
for j=1:400
l=l+1;
y(l,:)=[t+x(1,l).*z(1,:)];
end
for i=1:301
r=r+1;
mean(r)=sum(y(:,i))/400;
end
plot(mean,'o'),grid
title('The Mean of the signal')
ylabel('Mean')
xlabel('Number of realizations')
採用された回答
その他の回答 (1 件)
Walter Roberson
2011 年 5 月 31 日
1 投票
Where do you initialize "r" ?
Please do not name a variable "mean": you will almost certainly encounter conflicts with the built-in function by that name.
With regards to "matrix dimensions must agree": your subexpression 2*pi*100*(0:1/300:1) will be a vector of length 301, and you try to add to that x, which is length 400. I do not know what you want to do so I cannot really suggest a solution... but it might involve bsxfun()
カテゴリ
ヘルプ センター および File Exchange で Language Fundamentals についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!