Calculate a matrix based on value from another matrices

1 次查看(过去 30 天)
Hi. I want to calculate new value in matrix C and based on conditions from value of matrix P and R.
R=
[1 -0.136 0.036
-0.136 1 -0.327
0.036 -0.32 1]
P=
[1 1.02385610592401e-07 0.155888059376484
1.02385610592401e-07 1 5.36959056693074e-39
0.155888059376484 5.36959056693074e-39 1]
significant = zeros(size(P)) ;
significant(P<0.05) = 1 ;
positives=zeros(size(R));
positives(R>0) = 1 ;
I want to calculate C like this,
-1- In same row and column, I want to make value 1, if both matrices is one, and else will become zero.
Can you help me? Thanks

回答(1 个)

Andrei Bobrov
Andrei Bobrov 2017-7-6
编辑:Andrei Bobrov 2017-7-6
n = size(P,2);
pp = P < .05;
C = sum(pp,2)/n;
[i1,j1] = find(pp.*(1:n));
E = cellfun(@(x)strjoin(x,','),accumarray(i1,j1,[],@(x){sort(D(x))}),'un',0);
At new edition of question
R = [1 -0.136 0.036
-0.136 1 -0.327
0.036 -0.32 1];
P = [1 1.02385610592401e-07 0.155888059376484
1.02385610592401e-07 1 5.36959056693074e-39
0.155888059376484 5.36959056693074e-39 1];
C = P < 0.05 & R > 0

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by