For loop and indexing combined?
5 ビュー (過去 30 日間)
古いコメントを表示
I think I'm nearly there with this code.
close all;
clear all;
l=0.33;R=100;T=68;m=0.000125;w0=0.1;t=0;mu=m/l;c=sqrt(T/mu);r=2;x0=l/r;
x=linspace(0,0.33,10)
iter=1;
for n=1:5000;
wxt=((4*w0)/pi)*exp(-R*t)*((l/(pi*n^2*x0))*sin((n*pi*x0)/l))*sin((n*pi*x(1))/l)*cos((c*n*pi*t)/l);
wxtrec(n)=wxt;
iter=iter+1;
end
w=sum(wxtrec)
What I actually want is for the code to repeat for each value of x - instead of just for the first indexed value - x(1) - as it is now.
Right now, w, is correct for x(1). Is it possible to set up a new outer for loop, which uses subsequent values of x ie. x(1), x(2) etc. instead of just using x=1,2,3,4..?
0 件のコメント
採用された回答
Walter Roberson
2012 年 1 月 10 日
Yes, you had a suitable nested loop in one of your previous versions of this code.
Note: you never use iter so you might as well get rid of it.
0 件のコメント
その他の回答 (1 件)
Tom
2012 年 1 月 10 日
1 件のコメント
Walter Roberson
2012 年 1 月 10 日
The .' is transpose, converting the row vector (1:5000) in to a column vector.
bsxfun is the Binary Scalar Expansion Function routine; see your documentation.
@times is a function handle to the built-in element-by-element multiplication routine more commonly known as .*
For animation, please see http://www.mathworks.com/help/techdoc/creating_plots/f10-1460.html
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!