Effacer les filtres
Effacer les filtres

For loop, two variables

1 vue (au cours des 30 derniers jours)
Jin
Jin le 5 Fév 2014
Commenté : Jin le 5 Fév 2014
Hello,
I am new to the matlab and just start using it. Here is my first task and I am stuck.
I was using a for loop to calculate the changing Temperature with Time dT(i) = dT(i-1)*t where t = (1:100), and i=(2:100), start point dT(1) = 0.35
Here is my script: i = 1 dt(i)=0.35 i = 2:100; for t=1:100 dt(i,t)=dt(i-1)*t; end; plot (dt)
As in result, there are 100 of curves.
Help!!!

Réponse acceptée

Amit
Amit le 5 Fév 2014
Modifié(e) : Amit le 5 Fév 2014
dT = zeros(100,1); % Initalize
dT(1,1) = 0.35;
for j = 2:100
dT(j,1) = dT(j-1,1)*j;
end
plot(dT);
The reason you get 100 curves, because dT(i,t) where i = 2:100 simply suggests that there are 100 rows and with every loop you add a new column for each row with some scalar value calculated.
  1 commentaire
Jin
Jin le 5 Fév 2014
Hello Amit,
Thank you so much, it worked.
Thank you again J

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by