Save Function Output in a loop
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello,
I have a series of Inputs into a Function Input = (1,2,3). These Inputs are saves as a vector. Now I want to save the Output (several Values )for each Input with a while loop.
E.g The Output of the Functions consists out of 4 Values : ChargeLevel, Vbattery, Ibattery, Rbattery
But I always get an error. How to I properly save it into a variable so I have a table afterwards like this :
Input No. ChargeLevel Vbattery Ibattery Rbattery
1 100 25 10 5
.....
Input = ( 1, 2,3);
i=1;
while i<=3
z=AC.secondseg_exp( Input(i), timefirst, time);
i=i+1;
time=time+timefirst;
end
0 Kommentare
Antworten (1)
Geoff Hayes
am 27 Mai 2019
David - what is the error? Which are the output parameters (in your above code) that you want to save on each iteration of the loop? Just the z? If so, then try
Input = [1, 2, 3]; % <---- note the square brackets
i=1;
zData = zeros(3,4);
while i<=3
z(i,:) = AC.secondseg_exp( Input(i), timefirst, time);
i = i + 1;
time = time + timefirst;
end
I'm assuming that the output from AC.secondseg_exp is a 1x4 array. If not, then you will need to adjust your code.
Note that you could replace the while loop with a for loop.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!