For Loops and Plotting

1 次查看(过去 30 天)
Alex
Alex 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 CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by