For Loops and Plotting

조회 수: 2 (최근 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 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