Loop question in code
Afficher commentaires plus anciens
I have a code which runs a certain number of calculations and then displays the answer.
However what I want to do is tell the code to check with the vector created is a certain size, and if this check fails it goes back to a certain point in the code, adding a number to an initial variable and starting again.
I was wondering if there was a way to do this with something like a 'return' function
I don't think if or for loops are what I want
I have included my code as an example
%%Calculation to assess water temperature around the plant
C_pd = Specific_Heat(T_d,X_d);
C_pb = Specific_Heat(T_b,X_b);
e = 0.01;
f = 0.001;
k = 60; % Initial Minimum Value of T_f
l = 70; % Initial Maximum Value of T_F
m = 30; % Initial Minimum Value of T_o
n = 40; % Initial Maximum Value of T_f
i = 1;
Time1 = clock;
w = 3.6; % Error Factor
Return to here
for z = 1:3
g = 1/10^w;
for T_f = k:e:l
C_pf = Specific_Heat(T_f,X_f);
a = M_f*C_pf*(T_f-T_cw);
for T_o = m:f:n
b = M_d*C_pd*(T_d-T_o) + M_b*C_pb*(T_b-T_o);
if abs(a-b)<g
T(1,i) = T_f;
T(2,i) = T_o;
i=i+1;
end
end
end
k = min(T(1,:));
l = max(T(1,:));
m = min(T(2,:));
n = max(T(2,:));
e=e/10;
f = f/10;
w=w+1;
end
Time2 = clock;
size(T);
if size(T) == [2 1];
disp('T_f (68) = ')
disp(T(1,:))
disp('T_o (36) = ')
disp(T(2,:))
if T(1,:) == 68 % Error check
else
T_fdiff = T(1,:) - 68
end
if T(2,:) == 36
else
T_odiff = T(2,:) - 36
end
else
disp(size(T))
w = w + 0.01;
Loop from here
end
clock = etime(Time2,Time1)
Any thoughts?
Thanks in advance
1 commentaire
Walter Roberson
le 29 Déc 2011
There is no such thing as an "if loop". There are for loops, while loops, and if statements.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!