Getting one field data using other field in struct
이전 댓글 표시
Hello, I have a structure

I want to get the data of 2nd field but not using app.temp.Channel(2).data
I want to use the name field instead.
something like
mydata = app.temp.Channel.data(app.temp.Channel.name == 'U1');
but I have error (Error using == ; Too many input arguments).
May I know some suggestions, How to do this in a simple manner without using complex for loops.
댓글 수: 11
John D'Errico
2020년 2월 13일
You posted the same question 3 times. I'll close two of them.
Temu Gautama
2020년 2월 13일
Does this work?
app.temp.Channel.('U1')
Timon Rayis
2020년 2월 13일
Timon Rayis
2020년 2월 13일
Temu Gautama
2020년 2월 13일
Ah, sorry, misinterpreted the table. Then it should be something like this:
mydata = app.temp.Channel.data( cellfun(@( x )strcmp( x, 'U1' ), {app.temp.Channel(:).name} ));
Timon Rayis
2020년 2월 13일
편집: Timon Rayis
2020년 2월 13일
Temu Gautama
2020년 2월 13일
Hmm let's see
{app.temp.Channel(:).name}
should give you
ans =
'U1' 'U2' 'U3'
So if you do the cellfun-strcmp
cellfun(@( x )strcmp( x, 'U1' ), {app.temp.Channel(:).name} )
it should yield
ans =
1 0 0
which is then used for (logical) indexing. So I don't really see where the error is coming from. Could you try these lines separately?
Timon Rayis
2020년 2월 13일
Timon Rayis
2020년 2월 13일
편집: Timon Rayis
2020년 2월 13일
Timon Rayis
2020년 2월 13일
Timon Rayis
2020년 2월 13일
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!