Effacer les filtres
Effacer les filtres

How do I make empty lists in MATLAB Live Script and append to it?

100 vues (au cours des 30 derniers jours)
NiNa
NiNa le 1 Juil 2018
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.

Réponses (1)

Madeline Gardner
Madeline Gardner le 3 Juil 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

Catégories

En savoir plus sur Call Python from MATLAB dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by