fprintf statement with multiple looping variables.

6 visualizzazioni (ultimi 30 giorni)
Tim
Tim il 25 Mag 2014
Risposto: Tim il 25 Mag 2014
Hi, I need to print out a statement that has multiple looping variables with different iterations. I am pretty sure I cannot use the "for" loop statement here, but i'm unsure what else I can do. I need to print (probably using fprintf) iterations of something like this:
ELSE IF (TIME(1) <= 3.419999e+00 ) THEN
FLUX(1)=AMG*EXP(-2*(((COORDS(3)+V*TIME(1)- 6.498 )**2+(COORDS(1)- 0.2484 )**2)/(R**2)) FLUX(2)=0.0
The numbers in bold are my 3 variables. The first number (3.419999e+10) increases by a value of 0.001579 per increment, the second number (6.498) increases by 0.0012 per increment and the third increases by 0.0009 per increment. The next statement should read:
ELSE IF (TIME(1) <= 3.421578e+00 ) THEN
FLUX(1)=AMG*EXP(-2*(((COORDS(3)+V*TIME(1)- 6.4992 )**2+(COORDS(1)- 0.2493 )**2)/(R**2)) FLUX(2)=0.0
Can anyone show me how to create 3 different variables, with different iterations per loop step? Thank you!!!

Risposte (2)

TS
TS il 25 Mag 2014
if i understand your question correctly, you can use a for loop. a simple example:
a = 3.419999e+00;
b = 6.498;
c = 0.2484;
a_inc = 0.001579;
b_inc = 0.0012;
c_inc = 0.0009;
for i=0:10
a_current = a+i*a_inc;
b_current = b+i*b_inc;
c_current = c+i*c_inc;
disp(['(a,b,c) = ' num2str([a_current b_current c_current])])
end
there are also many other ways to do this..

Tim
Tim il 25 Mag 2014
Thank you! Just about there, how would you incorporate the variables into the quoted text to make it similar to my example?

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by