How to run a script multiple times changing one variable?
古いコメントを表示
I want to be able to run the below script multiples times, each time for a different value of Dd. Ending up with a file that gives me Scrit for each Dd.
Do I do this using a for loop?
% Using dry diameter in um
K=0.5;
Dd=0.1;
sigma=0.072;
T=298.15;
Mw=18.01528;
Pw=0.997;
R=8.3143;
% Define functions
D=linspace(0.1,5,500);
% Define exponential constants as a function
x=(4*sigma*Mw)/((R*T*Pw));
S=((D.^3-Dd^3)./(D.^3-Dd^3+Dd^3*K)).*exp(x./D);
plot(D,S)
% Labelling the axes
xlabel('Wet Diameter (um)')
ylabel('Saturation')
title('Kohler Curves for Different Diameter')
% Limits for axes
ylim([0.98,1.05])
xlim([0.1,5])
% Finding the maximum in a data set
Scrit=max(S)
Dmax=D(find(S==Scrit))
I had a go and this is what i have so far:
for Dd=0.01:0.01:5;
D=linspace(0.1,5,500);
x=(4*sigma*Mw)/((R*T*Pw));
S=((D.^3-Dd^3)./(D.^3-Dd^3+Dd^3*K)).*exp(x./D); % Loop
end
1 件のコメント
Geoff Hayes
2019 年 2 月 28 日
Alice - yes, you could use a for loop (though you would need to store the results (i.e. the S) for each iteration so that you could plot all results outside of the loop. Note that in your code, you could move the initialization of D and x outside of the loop since neither depends upon the value of Dd.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!