How to make empty lists in MATLAB Live Script and append to them both outside of a loop and inside one? [closed]

Multi tool use
Multi tool use


How to make empty lists in MATLAB Live Script and append to them both outside of a loop and inside one? [closed]



The three list I want to make are the following and I'm not sure how it's done in MATLAB.


na =
nb =
t



Outside of the list I want to append the follwoing:


NA = input('Enter intial number of atoms of A > ');
NB = input('Enter intial number of atoms of B > ');
tau_a = input('Define decay constant of A >');
tau_b = input('Define decay constant of B >');
time = input('the total time >');
dt = input('Define time increment >');



I've to append the values like so:


na = [na, NA]
nb = [nb; NB]
t = [t, 0]



Finally, inside the loop I have tried appending values like this:


for i = int16(time/dt)
nai = na[i]-(na[i]/tau_a)*dt
nbi = nb[i]+((na[i]/tau_a)-(nb[i]/tau_b))*dt
ti = t[i]+dt
na = [na, nai]
nb = [nb, nbi]
t = [t, ti]
end



But it is not working. It does not want to append the values. The error messages I get are:



"Parse error at '[': usage might be invalid MATLAB syntax."



"The variable 'na, nb, and t' appears to change size on every loop iteration. Consider preallocating for speed."



"Unbalanced or uexpected parenthesis or bracket"



This question appears to be off-topic. The users who voted to close gave this specific reason:





Have you tried anything to write code in MATLAB? Please show us that. We are not going to translate it into MATLAB for you from scratch. And please don't append. Appending in a loop adversely affects the performance.
– Sardar Usama
Jul 1 at 13:43






I've now edited to what I have done in MATLAB
– Nina
Jul 1 at 14:06





MATLAB indexing starts at 1, not at zero. If you had looked at the error message, you would have learned that the problem is in indexing, not in appending. — When you post here, please include the actual error messages you get from the code. “It does not want to do it” is not a good diagnostic. We’ve all seen these error messages many times, and it’s easy for us to point at issues when we see those.
– Cris Luengo
Jul 1 at 14:17






Can't I make it start at 0? All MATLAB says is: "Unbalanced or unexpected parenthesis or bracket" and that the variables (na, nb, and t) "appears to change size on every loop iteration"
– Nina
Jul 1 at 14:21






t is not a valid variable declaration. The error messages should be telling you exactly where the issues are.
– excaza
Jul 1 at 18:05



t




K,Yx,FgWoEV65DEql7F6Qm4,X v,SSzGIRup,aVSe5hd,q9PyZbjEnLSQDu,5FN1 5aD,Psdu 3KIy vgx DgCsU LndEsB4MfHzBTaSW,fw9Bi
MgoL3dM,cq8nwN8hhbAW8nWfM,b4YbIo RkyBPAmCtrz6 EL567SJ XqE

Popular posts from this blog

Rothschild family

Cinema of Italy