Search variable names inside the cell array with struct items

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

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개)

카테고리

도움말 센터File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

질문:

2023년 1월 2일

댓글:

2023년 1월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by