Use strcmp() based on part of the row name in structure

Hi everyone,
I have a structure (DATA) with 3 fields (name, folder, data (tables)). There are many rows with names (field name) in a pattern as follows :
'London_FirstVariable_Water.txt'
'London_SecondVariable_Fire.txt'
'London_ThirdVariable_Air.txt'
'London_FourthVariable_Earth.txt'
'Paris_FirstVariable_Water.txt'
'Paris_FourthVariable_Fire.txt'
'Paris_FifthVariable_Air.txt'
'Paris_ThirdVariable_Earth.txt'
etc.
I want to make a new structure that keeps only the rows with 'XXX_XXX_Fire.txt', no matter what is before.
I have tried this :
FIRE = DATA(strcmp({DATA.name}, '%s_%s_Fire.txt'))
which obviously doesn't work.
However, it works like this :
FIRE = DATA(strcmp({DATA.name}, 'London_SecondVariable_Fire.txt'))
but this way I only get this one row, and I would rather not have to write each name in separate lines but something to get all the rows with a name containing Fire.txt
Any idea ?
Thanks for your help :)

 채택된 답변

Stephen23
Stephen23 2022년 4월 7일

0 개 추천

댓글 수: 4

Thank you for your answer. I do get a vector with index 1 if the name ends with Fire.txt and 0 otherwise, but it still doesn't help remove the other rows in my structure because this binary vector is not in the structure...
I assume that if I could insert this binary vector inside my structure as a new field, say named 'index', then I could do it this way :
FIRE = DATA(strcmp({DATA.index}, 1))
but I cannot manage to attribute a 0 or 1 value to the rows in the struct...
@Loriann Chevalier: you then use that logical vector as a logical index to remove the parts of the array/s that you do not want. Much like you showed in your question.
Alright I see, thanks for your help ! :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by