How can I find the same value by using cellfun?
Show older comments
condition = {EEG.epoch.eventtype};
%condition contains a lot of cell, and each cell have two values which either {11 1} or {12 2}.


correct_11trial = {'11' '1'};
correct_11 = cellfun(@(x) isequal(x,correct_11trial), condition(1,:));

%so I dfined the correct_11trial as {11 1}, and what I am looking for is to get the information that which
% cell is similar as correct_11trials in whole condition.
%However, the reuslt gave me all zero.
Can anyone help me to provide the instruction?
Thank you
Answers (1)
condition = {[11,1],[11,1],[12,2],[12,2],[11,1]};
idx = cellfun(@(v)isequal(v,[11,1]),condition);
Your code didn't work becuase you were search for characters but your data are numeric.
correct_11trial = {'11' '1'};
% Should be
correct_11trial = [11 1];
4 Comments
Yu-Jung Tsai
on 17 Jan 2020
Adam Danz
on 17 Jan 2020
Glad I could help!
If it worked, you can mark this as answered by pressing the blue accept button.
If you found a better solution, it would be helpful to future visitors to create a new answer.
If you still need some help, please provide an update in the form of a comment.
Yu-Jung Tsai
on 18 Jan 2020
Adam Danz
on 18 Jan 2020
Weird. Don't worry about it :)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!