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!