필터 지우기
필터 지우기

How to find a string in the following cell structure?

조회 수: 10 (최근 30일)
Mr M.
Mr M. 2018년 10월 15일
편집: Stephen23 2018년 10월 15일
I have s{1}.name = 'abc', s{2}.name = 'xyz', ..., s{n}.name = 'something'. And I would like to know the existance of a strin mystr ='aaa' among these names, and its index. Is it possible to do without a for cycle?

답변 (2개)

madhan ravi
madhan ravi 2018년 10월 15일
편집: madhan ravi 2018년 10월 15일
  댓글 수: 1
Mr M.
Mr M. 2018년 10월 15일
편집: Mr M. 2018년 10월 15일
dot indexing is not supported for variables of this type
synatax error:
mparams{1}.name = 'a'; params{1}.value = 13; params{2}.name = 'b'; params{2}.value = 42; {params.name}

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


Stephen23
Stephen23 2018년 10월 15일
편집: Stephen23 2018년 10월 15일
Storing lots of separate scalar structures in a cell array is less convenient than just using one non-scalar structure. You should replace the cell array of scalar structures with one single non-scalar structure, then your task is trivial:
c{1}.name = 'abc';
c{2}.name = 'xyz';
c{3}.name = 'something';
s = [c{:}] % convert cell of scalar structures to non-scalar structure.
x = strcmp('xyz',{s.name})
Even better would be to avoid the cell array entirely, and just use a non-scalar structure right from the start:
s(1).name = 'abc';
s(2).name = 'xyz';
s(3).name = 'something';
x = strcmp('xyz',{s.name})
Read more about how this works:

카테고리

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