How can I do the same calculation multiple times for specified values of a variable

6 次查看(过去 30 天)
I am calculating compositonal profiles with a very simple version of the diffusion equation.
I want to do the same calculation several times and store the values in the workspace (ideally as mutliple columns for a single variable).
I have figured out the followng way to do it - but I am sure that there is a more elegant solution to my problem:
x = 0:1:100;
Co = 22;
t1 = 30000;
t2 = 60000;
t3 = 120000;
D = 0.001;
C1 = Co*erf(x/(D*t1).^0.5);
C2 = Co*erf(x/(D*t2).^0.5)
C3 = Co*erf(x/(D*t3).^0.5)
plot(x,C1, x, C2, x,C3)
Thanks
Cliff

采纳的回答

Star Strider
Star Strider 2020-2-14
Thios does the same as yoiur code, using a loop, and a simplified plot call:
x = 0:1:100;
Co = 22;
t1 = 30000;
t2 = 60000;
t3 = 120000;
t = [t1 t2 t3];
D = 0.001;
for k = 1:numel(t)
C(k,:) = Co*erf(x/(D*t(k)).^0.5);
end
figure
plot(x,C)
grid
It is may be a bit more efficient. I did not assess that specifically.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Title 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by