Get the data in rows and/or columns from a matrix in a MEX file

3 ビュー (過去 30 日間)
gire
gire 2013 年 12 月 16 日
コメント済み: gire 2013 年 12 月 17 日
Hello,
I am writing a MEX routine in which I need to multiply a row and a vector from a matrix (among other things). In Matlab's language it would look like this:
tmp(i) = A(i,:) * A(:,i)
I want to use the ddot BLAS function. Is there a MEX function to get a complete row/column from a matrix?

採用された回答

James Tursa
James Tursa 2013 年 12 月 16 日
The signature for ddot from this link:
is:
DOUBLE PRECISION FUNCTION DDOT(N,DX,INCX,DY,INCY)
* .. Scalar Arguments ..
INTEGER INCX,INCY,N
* ..
* .. Array Arguments ..
DOUBLE PRECISION DX(*),DY(*)
* ..
So you can just give the starting address (DX and DY) and increment (INCX and INCY) of each, no need to extract anything. E.g., a code snippet for calling to do the basic calculation could be this:
// Assume 1st input prhs[0] is A, 2nd input prhs[1] is i
mwSignedIndex N, I, ONE;
double *pr, *DX, *DY;
double tmp;
ONE = 1;
N = mxGetN(prhs[0]); // assume input matrix is square
pr = mxGetPr(prhs[0]); // assume input matrix is double
I = mxGetScalar(prhs[1]);
DX = pr + (I-1); // Use 0-based indexing
DY = pr + (I-1)*N;
tmp = ddot(&N,DX,&N,DY,&ONE); // A(i,:)*A(:,i)
  1 件のコメント
gire
gire 2013 年 12 月 17 日
Thanks for the code snippet.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWrite C Functions Callable from MATLAB (MEX Files) についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by