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 Comments

You posted the same question 3 times. I'll close two of them.
Does this work?
app.temp.Channel.('U1')
@Temu Gautama, No it does not work.
Reference to non-existent field 'U1'.
@John, No I did not submit the question 3 times. there is a delay with the community site now, I don't know why. While autosaving the question, it is posted multiple times I guess.
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} ));
@Temu Gautama, I am getting error again.
Expected one output from a curly brace or dot indexing expression, but there
were 3 results.
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?
{app.temp.Channel(:).name}
For this line, I am getting
ans =
1x3 cell array
{'U1'} {'U2'} {'U3'}
Also, for
cellfun(@( x )strcmp( x, 'U1' ), {app.temp.Channel(:).name} )
I am getting
ans =
1x3 logical array
1 0 0
but when I try
mydata = app.temp.Channel.data( cellfun(@( x )strcmp( x, 'U1' ), {app.temp.Channel(:).name} ));
It says
Expected one output from a curly brace or dot indexing expression, but there
were 3 results.
@Temu Gautama Thanks.
I made a small change (.data) in that line comes at last.
And now I can get the data.

Sign in to comment.

Answers (0)

Categories

Asked:

on 13 Feb 2020

Edited:

on 13 Feb 2020

Community Treasure Hunt

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

Start Hunting!