Counting repeated values paired with other repeated values and placing those counts in an array
古いコメントを表示
I have a dataset in which different stimulus levels are presented multiple times. So far I've managed to boil this down using unique and arrayfun to produce one column of unique values and a second column stating how many times the unique value was presented during the experiment. Here's my code for that, which I obtained through looking in MATLAB's FAQs regarding unique:
if true
myfastrepeat1(:,1) = unique(myfasttotal1(:,1));
myfastrepeattemp = arrayfun(@(x)length(find(myfasttotal1(:,1) == x)), unique(myfasttotal1(:,1)), 'Uniform', false);
myfastrepeat1(:,2) = cell2mat(myfastrepeattemp);
end
So say I have three incidences of stimulus -0.5768 - of those three presentations, the observer got two presentations correct. In my myfasttotal1 file, this would be represented thus:
[-0.5768, 0; -0.5768, 1; -0.5768, 1]
Having got this far, I'm now a bit stuck as to how to tackle creating a new column in myfastrepeat1 which states how many presentations were correct for each unique stimulus. I'm not sure whether I should still be using arrayfun for this or using histc, or indeed going down the indexing route. I figure that provided I can get MATLAB to consider each set of repeated stimulus values as a group, I could then get the count of 1 for each group, so in the above example the count of 1s would be 2, representing the number of correct answers.
Thankyou in advance for any advice you can give, and if you need more elaboration on what I'm trying to do, let me know!
5 件のコメント
Sean de Wolski
2012 年 8 月 15 日
編集済み: Sean de Wolski
2012 年 8 月 15 日
Two things:
- Can you provide a sample dataset we can try?
- arrayfun is evil. Just use histc on the third output from unique:)
[uval,~,idx] = unique(x);
n = histc(idx,1:numel(uval))
Matt Fig
2012 年 8 月 15 日
ARRAYFUN is evil, Sean de. I am glad I am not the only one who thinks so!
Anon
2012 年 8 月 16 日
Why is ARRAYFUN bold evil?
Marianne
2012 年 8 月 16 日
Sean de Wolski
2012 年 8 月 16 日
@Anon, it's slow and confusing and thus has no redeeming values.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!