필터 지우기
필터 지우기

Search variable names inside the cell array with struct items

조회 수: 3 (최근 30일)
Ahmet Hakan UYANIK
Ahmet Hakan UYANIK 2023년 1월 2일
댓글: Jiri Hajek 2023년 1월 3일
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
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 CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by