How can I link elements in corresponding rows of two matrices of the same dimension?
2 ビュー (過去 30 日間)
古いコメントを表示
Hey everyone! I need a bit of help with something. I'm more like a beginner in learning Matlab and I have some trouble with creating a program.
I have 2 matrices of the same dimension:
A = blk.visDiff(:,1);
B = blk.responseMade(:,1);
And I want to count for each element of A the number of times the corresponding element in B is 1 (when I say corresponding element I mean that if I would have merged the two matrices in one matrix with 2 columns, the 2 "corresponding" elements will be in the same row of the final matrix), and then divide the number calculated by the total times of A being equal to each specific value.
For example:
calculate how many times A = 100 and B = 1 --> and then divide this number by the number of times A = 100
I always need to calculate this for B=1, but there are multiple values of A (11 values to be more exact). I want plot in the end the each values of A (e.g. 1, 80, 60..., -60, -80, -100) against the fraction of number of times when B was 1.
How can I write this in a program?
(The two matrices can also be merged in the program, this aspect is not important)
採用された回答
Star Strider
2019 年 1 月 9 日
See if the findgroups (link) and splitapply (link) functions will do what you want. (They were introduced in R2015b.)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!