[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Matrix manipulation help

From   "Susan Olivia" <>
Subject   st: Matrix manipulation help
Date   Wed, 01 Apr 2009 16:11:57 -0700

Dear all,

I would like to create a binary matrix (say matrix B) using
the existing information from current matrix A. 

Specifically, for each cell (i,j) of matrix B, I want to
replace its value with 1 if the value of the corresponding
cell (i,j) of matrix A is within its k-th nearest neighbors
value; and 0 otherwise. 

I only can get to the point where replacing each cell of
matrix B to 1 if the value of the corresponding cell of
matrix A is < THRESHOLD. Below is what am currently
experimenting with. If I can get any tips how to efficiently
improve the current code and correctly handle this, I
greatly appreciate it.


local N=_N

mkmat var1-var100, matrix(DistMatrix)

matrix AAA=DistMatrix

mkmat _all, matrix(A)

matrix B=J(`N',`N',0)

mata: mata clear


void underbar(string scalar A,

real scalar thresh)


real matrix B

real scalar i

B = (st_matrix(A) :< thresh)

for(i=1; i<=rows(B); i++) {

B[i,i] = 0


st_matrix("B", B)



mat list A

mata: underbar ("A", 50)

matrix list B

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index