Search variable names inside the cell array with struct items
5 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Jiri Hajek
2023 年 1 月 3 日
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.
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Cell Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!