Search variable names inside the cell array with struct items
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello,
I have a cell variable called "data(685x1)", each row has a struct and each struct also has struct inside(e.g. timeseries). What I want corresponds in python is as follows:
station_names = []
ids = []
for item in data.iterrows():
for d in item[1].timeseries:
ts_shortname = d.get("shortname")
if ts_shortname == 'Q':
station_names.append(item[1].longname)
ids.append(item[0])
In MATLAB I am able to see the items(shortname and longname) as follows for 10th row:
data{10,1}.timeseries.shortname
but when "timeseries" has more than 1 row, I have to see the item like
data{10,1}.timeseries{1,1}.shortname
and I do not know how many rows it contains in timeseries struct, it varies. In python it simply extracts all the shortnames consist in timeseries struct. Ofc it can be possible with so many if statements and for loops but how can I do the same in python code above more simplier in MATLAB?
Thank you
1 Commento
Jiri Hajek
il 3 Gen 2023
HI, seems like you need some basic intro to MATLAb work with arrays. You can of course find "how many rows it contains in a timesireis struct" using the size function. But you should also get acquainted with array indexing. Of course the syntax is different in MATLAB, but generally many things are doable as one-liners, without for loops. If you have a specific question, which I didn\t spot in your post, please ask.
Risposte (0)
Vedere anche
Categorie
Scopri di più su Cell Arrays 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!