How can I find the same value by using cellfun?

25 ビュー (過去 30 日間)
Yu-Jung Tsai
Yu-Jung Tsai 2020 年 1 月 16 日
コメント済み: Adam Danz 2020 年 1 月 18 日
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

回答 (1 件)

Adam Danz
Adam Danz 2020 年 1 月 16 日
編集済み: Adam Danz 2020 年 1 月 17 日
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 件のコメント
Yu-Jung Tsai
Yu-Jung Tsai 2020 年 1 月 18 日
Hi Adam,
I have tried to accept the answer, but I don't know why whenever I press the button that always show "Unable to complete the action because of changes made to the page. Reload the page to see its updated state."
I had reload the page for thousand times, but it didn't work.
Adam Danz
Adam Danz 2020 年 1 月 18 日
Weird. Don't worry about it :)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by