fprintf statement with multiple looping variables.

4 ビュー (過去 30 日間)
Tim
Tim 2014 年 5 月 25 日
回答済み: Tim 2014 年 5 月 25 日
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!!!

回答 (2 件)

TS
TS 2014 年 5 月 25 日
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 2014 年 5 月 25 日
Thank you! Just about there, how would you incorporate the variables into the quoted text to make it similar to my example?

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by