How to use one matrix to constrain another matrix of the same size?
1 view (last 30 days)
Show older comments
I am doing pairwise correlation analysis and ran into the following problem. I have a n by n matrix of p values and a corresponding n by n matrix of r. I want to keep every entry in the r matrix that has a p value less than 0.01, and make all the other entry either 0 or NaN. In other words, I have matrix A and B; if Ai,j then keep Bi,j; if Ai,j=0.01, then Bi,j=0. Can someone please help me with how to code this? Thank you!!
0 Comments
Accepted Answer
James Tursa
on 6 Aug 2015
Edited: James Tursa
on 6 Aug 2015
If I understand your question correctly, then
x = A < 0.01; % Logical indexing for those elements you want to keep
B(~x) = nan; % Set the others to nan (or 0 if you want)
0 Comments
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices 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!