For Loops and Plotting

1 回表示 (過去 30 日間)
Alex
Alex 2014 年 12 月 7 日
回答済み: Star Strider 2014 年 12 月 7 日
The following is a for loop. Just checking to make sure it is set up right. Also, when I go to plot this array and an array from 0 to 250 by 0.5, it doesn't work. In my code, it is "plot(timearray,resultarray)" and doesn't work. Any suggestions?
Thanks
for i = (0:.5:250)
resultarray = (((array(6,:) * array(2,:)) / (constant - array(6,:))) * (exp(-array(6,:) * i * 3600) - exp(-constant * i * 3600))) + (array(1,:) * exp(-constant * i * 3600));
end

採用された回答

Star Strider
Star Strider 2014 年 12 月 7 日
You need to subscript ‘resultarray’, and also ‘timearray’, to create a vector out of each one:
for k1 = (0:.5:250)
resultarray(k1) = (((array(6,:) * array(2,:)) / (constant - array(6,:))) * (exp(-array(6,:) * i * 3600) - exp(-constant * i * 3600))) + (array(1,:) * exp(-constant * i * 3600));
end
I changed your loop index counter to ‘k1’ because MATLAB uses i and j as its imaginary operators.
That is particularly significant here, because if ‘i’ is an index will produce the exponent of a real argument, exp(-constant*i*3600), but if it you intend it to be the imaginary operator, will return cos(constant-3600)-i*sin(constant*3600).
I left it as ‘i’ in your calculation for ‘resultarray’ because I have no idea what you intend. Neither does MATLAB.

その他の回答 (0 件)

カテゴリ

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