How do I make empty lists in MATLAB Live Script and append to it?
101 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I want to make 3 empty list, in which I can append values to as shown in the following (The code is written in Python):
na=[]
nb=[]
t=[]
na.append(float(raw_input("the initial number of nuclei A:")))
ta=float(raw_input("the constant time of nuclei A:"))
nb.append(float(raw_input("the initial number of nuclei B:")))
tb=float(raw_input("the constant time of nuclei B:"))
tt=float(raw_input("the total time:"))
dt=float(raw_input("the time step:"))
t.append(0)
I do not know how this is done in MATLAB. Please help.
0 Commenti
Risposte (1)
Madeline Gardner
il 3 Lug 2018
Hello!
Luckily, Python and MATLAB have pretty similar syntax, so your code is actually going to look pretty similar! You'll be using the function input which, unlike Python, can actually return a float (or a 'double', which is one type of floating-point number in MATLAB) and not just a string. And adding to an array in MATLAB is also very easy, since MATLAB is designed around arrays, vectors, and matrices -- you can just put brackets around the original array and the new elements, like so [array, elem] to concatenate them.
So, your code will follow the general form:
na = []
x = input("the initial number of nuclei A:")
na = [na x] % No need to change the type of x
I hope that helps! Also, if you're new to MATLAB, there are some very helpful tutorials to get you started here: https://www.mathworks.com/help/matlab/getting-started-with-matlab.html
0 Commenti
Vedere anche
Categorie
Scopri di più su Call Python from MATLAB in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!