Storing the maximum value in each iteration

5 vues (au cours des 30 derniers jours)
Najeem Afolabi
Najeem Afolabi le 4 Déc 2020
Commenté : Najeem Afolabi le 4 Déc 2020
Hi all,
I'm trying to write some code where I use different values for a particular input parameter in the case v0. Ccstr1 is an array with 4 columns, I want to take the maximum value of each iteration in the third column and the plot it against the v0. Here's the code I have so far. Any ideas?
% array of zeros to be used to store max Cc values for each iteration
X = zeros(26,1);
for v0 = [0:2:50] %m^3/s
%ODE solver CSTR
[time, Ccstr1] = ode45(@diffcstrFEEDFLOW, timeSpan, initCon,[],v0);
X = max(Ccstr(:,3));
end

Réponse acceptée

VBBV
VBBV le 4 Déc 2020
Modifié(e) : VBBV le 4 Déc 2020
%rue
v0 = 0:2:50;
for i = 1:length(v0)
...
X(i) = max(Ccstr(:,3))
end
plot(v0,X)
Use the for loop index as above onside the loop
  1 commentaire
Najeem Afolabi
Najeem Afolabi le 4 Déc 2020
Thank you very much for you help. Code works.

Connectez-vous pour commenter.

Plus de réponses (1)

Ameer Hamza
Ameer Hamza le 4 Déc 2020
You are overwriting the value of X in each iteration of for-loop. Do something like this
v0 = [0:2:50];
X = zeros(size(x0));
for i = 1:numel(v0) %m^3/s
%ODE solver CSTR
[time, Ccstr1] = ode45(@diffcstrFEEDFLOW, timeSpan, initCon,[],v0(i));
X(i) = max(Ccstr(:,3));
end
  1 commentaire
Najeem Afolabi
Najeem Afolabi le 4 Déc 2020
Thank you very much! It works.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by