【问题标题】:mxGetIr makes my Matlab crashmxGetIr 使我的 Matlab 崩溃
【发布时间】:2013-07-24 21:20:50
【问题描述】:

我正在编写一个 MEX 文件,该文件涉及从 Matlab 读取稀疏矩阵,但每次运行程序时,Matlab 都会崩溃。然后我写了一个测试文件,发现问题正好出在mxGetIr命令上。我不知道为什么会这样。请帮助我...非常感谢!

我在 Mac OS X 10.8.1 的 Matlab 2013a 下工作。

#include "fintrh.h"

  subroutine mexFunction(nlhs, plhs, nrhs, prhs)

  mwpointer plhs(*), prhs(*)
  integer nlhs, nrhs

  integer temp, nzmax
  integer, dimension(2) :: dimx

  real, dimension (:), allocatable :: sr
  integer, dimension (:), allocatable :: irs, jcs

  mwpointer mxGetPr
  mwpointer mxCreateDoubleMatrix
  mwsize  mxGetM, mxGetN, mxGetNzmax

  mwpointer mxGetIr, mxGetJc

  mwpointer temp_pr, spr

  dimx(1) = mxGetM(prhs(1))
  dimx(2) = mxGetN(prhs(1))
  nzmax = mxGetNzmax(prhs(1))
  allocate(sr(1:nzmax))
  allocate(irs(1:nzmax))
  allocate(jcs(1:(dimx(2)+1)))
  temp_pr = mxGetPr(prhs(1))
  call getreal(temp_pr,sr,nzmax)

  temp_pr = mxGetJc(prhs(1))

  plhs(1) = mxCreateDoubleMatrix(nzmax,1,0)
  temp_pr = mxGetPr(plhs(1))
  call putreal(sr, temp_pr, nzmax)

  end

  subroutine real8toreal(x, y, size)
  integer size
  real*8 x(size)
  real y(size)
  do 10 i=1,size
     y(i)= x(i)
  10   continue
  return
  end

  subroutine getreal(pr,x,size)
  mwpointer pr
  integer size
  real x(size)
  real*8, dimension (:), allocatable :: temp
  allocate(temp(1:size))
  call mxCopyPtrToReal8(pr,temp,size)
  call real8toreal(temp,x,size)
  deallocate(temp)      
  return
  end

  subroutine putreal(x,pr,size)
  mwpointer pr
  integer size
  real x(size)
  real*8, dimension (:), allocatable :: temp
  allocate(temp(1:size))
  call realtoreal8(x,temp,size)
  call mxCopyReal8ToPtr(temp,pr,size)
  deallocate(temp)      
  return
  end

【问题讨论】:

  • 你确定你提供给函数的输入确实是稀疏的吗?使用mxIsSparse 在内部检查它。
  • 谢谢!我查了一下,它是一个稀疏矩阵...

标签: matlab fortran mex


【解决方案1】:

检查the documentation后,我想你可能需要换一种方式称呼它。

从那里我猜是这样的:

mwPointer mxGetIr(pm)
mwPointer pm

【讨论】:

    猜你喜欢
    • 2015-05-14
    • 1970-01-01
    • 2015-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多