For Loops and Plotting
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Alex
am 7 Dez. 2014
Beantwortet: Star Strider
am 7 Dez. 2014
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
0 Kommentare
Akzeptierte Antwort
Star Strider
am 7 Dez. 2014
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!