Matlab 版 (精华区)

发信人: hahn (有奇~~Not Over But another Start...), 信区: Matlab
标  题: [合集] 求助:求助利用mex文件的问题
发信站: 哈工大紫丁香 (Wed Jan 24 00:58:24 2007), 站内

────────────────────────────────────────
  laserslp (hongwai)               于  (Wed Aug 23 10:01:51 2006)  说道:

有一个上百万的循环,利用matlab需要特别长时间,想用mex文件实现,但运行后出现错,
请大家帮忙。目的:将矩阵x中小于-4000和大于-4000的值分开,然后赋给两个矩阵y1和y
2,然后将y1和y2调回matlab中.程序如下:
#include "mex.h" 
void mydata(double y1[],double y2[],double x[])

   int i,l2,m2;
   for (i=1;i<=100;i++)
       if (x[i]<=-4000)
       {l2=l2+1;
       y1[l2]=x[i];}
       else  {m2=m2+1;
           y2[m2]=x[i];}

}

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs 
[]) 

{
    double *x,*y1,*y2;
    x=mxGetPr(prhs[0]);
    y1=mxGetPr(plhs[0]);
    y2=mxGetPr(plhs[1]);
    mydata(y1,y2,x);
}
matlab调用程序如下:
cd d:\mywork
mex mydata.cpp
dir mydata.*

x=[-5633,-3585,-5889,-4097,-2305,-4097,-3073,-4865,-3329,-7169,-3841,-2561,-,.
..
   -2561,-4097,-3073,-6401,-3329,-2817,-4097,-2305,-4353,-2561,-5377,-3329,-,.
..
   -3585,-2305,-4097,-2817,-4353,-2817,-6657,-3841,-2305,-3841,-2561,-4097,-,.
..
   -6401,-3073,-3073,-3841,-2049,-4353,-3073,-5377,-3329,-5633,-3841,-2305,-,.
..
   -2817,-4609,-3585,-7169,-3841,-2049,-4353,-2817,-4097,-3073,-6145,-3585,-1]
;
%仅给出一部分值,实际上有上百万个
[y1,y2]=mydata(x)  

运行后提示出现错误:

------------------------------------------------------------------------
       Segmentation violation detected at Wed Aug 23 09:49:11 2006
------------------------------------------------------------------------

Configuration:
  MATLAB Version:   7.1.0.246 (R14) Service Pack 3
  MATLAB License:   161051
  Operating System: Microsoft Windows XP
  Window System:    Version 5.1 (Build 2600: Service Pack 2)
  Processor ID:     x86 Family 6 Model 10 Stepping 0, AuthenticAMD
  Virtual Machine:  Java 1.5.0 with Sun Microsystems Inc. Java HotSpot(TM) Cli
ent VM mixed mode
  Default Charset:  GBK

Register State:
  EAX = 00000000  EBX = 11de1bb0
  ECX = 0fe627a0  EDX = 00000002
  ESI = 00000000  EDI = 00cde660
  EBP = 00cdded4  ESP = 00cdded4
  EIP = 78502f16  FLG = 00010212

Stack Trace:
  [0] libmx.dll:_mxGetPr(0, 0x00cde660, 0, 0) + 6 bytes
  [1] mydata.mexw32:0x012e13f0(2, 0x00cde660, 1, 0x00cde6c0)
  [2] libmex.dll:_mexRunMexFile(2, 0x00cde660, 1, 0x00cde6c0) + 103 bytes
  [3] libmex.dll:private: void __thiscall Mfh_mex::runMexFileWithSignalProtect
ion(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(2, 0x00cde660, 1, 0
x00cde6c0) + 73 bytes
  [4] libmex.dll:public: virtual void __thiscall Mfh_mex::dispatch_file(int,st
ruct mxArray_tag * *,int,struct mxArray_tag * *)(2, 0x00cde660, 1, 0x00cde6c0)
 + 169 bytes
  [5] m_dispatcher.dll:public: virtual void __thiscall Mfh_file::dispatch_fh(i
nt,struct mxArray_tag * *,int,struct mxArray_tag * *)(2, 0x00cde660, 1, 0x00cd
e6c0) + 271 bytes
  [6] m_interpreter.dll:int __cdecl mdDispatch(int,char const *,int,struct mxA
rray_tag * *,int,struct mxArray_tag * *,class Mfh_MATLAB_fn * *)(648, 0x129670
c0 "mydata", 2, 0x00cde660) + 88 bytes
  [7] m_interpreter.dll:_inDispatchFromStack(648, 0x129670c0 "mydata", 2, 1) +
 800 bytes
  [8] m_interpreter.dll:enum opcodes __cdecl inDispatchCall(char const *,int,i
nt,int,int *,int *)(0x129670c0 "mydata", 648, 2, 1) + 145 bytes
  [9] m_interpreter.dll:int __cdecl inInterp(enum inDebugCheck,int,int,enum op
codes,struct inPcodeNest_tag volatile *,int *)(2, 0, 0, 0) + 2534 bytes
  [10] m_interpreter.dll:int __cdecl inInterPcodeSJ(enum inDebugCheck,int,int,
enum opcodes,struct inPcodeNest_tag *,int *)(2, 0, 0, 0) + 282 bytes
  [11] m_interpreter.dll:_inInterPcode(2, 0x784d6e7c, 0, 0) + 81 bytes
  [12] m_interpreter.dll:enum inExecutionStatus __cdecl in_local_call_eval_fun
ction(int *,struct _pcodeheader *,int *,struct mxArray_tag * * const,enum inDe
bugCheck)(0x00cdf278, 0x00cdf370, 2, 1) + 153 bytes
  [13] m_interpreter.dll:$L74683(0x784d6e7c, 0x0fdbbb20 "[y1,y2]=mydata(x)  ; 
 \n", 0, 0) + 184 bytes
  [14] m_interpreter.dll:enum inExecutionStatus __cdecl inEvalCmdWithLocalRetu
rnandtype(char const *,int *,enum inDebugCheck)(0x0fdbbb20 "[y1,y2]=mydata(x) 
 ;  \n", 0, 2, 0x00cdf3bc "D敉") + 69 bytes
  [15] m_interpreter.dll:_inEvalCmdNoEnd(0x0fdbbb20 "[y1,y2]=mydata(x)  ;  \n"
, 1, 255, 0) + 16 bytes
  [16] bridge.dll:enum inExecutionStatus __cdecl ThrowSignal(char const *)(0x0
fdbbb20 "[y1,y2]=mydata(x)  ;  \n", 0x7c80b529, 0x02317830, 0x02317830) + 60 b
ytes
  [17] bridge.dll:$L86781(0, 0, 0x784d6e58, 0x7c36b71f) + 432 bytes
  [18] mcr.dll:public: void __thiscall mcrInstance::mnParser(void)(271289, 0x5
05c3a44, 0x72676f72, 0x46206d61) + 93 bytes
  [19] MATLAB.exe:0x00401ca9(4194304, 0, 271289, 0x02317830)
  [20] MATLAB.exe:0x00403d9f(3211315, 3276849, 0x7ffd5000, 0x80873938)
  [21] kernel32.dll:0x7c816d4f(0x00403c1a, 0, 0, 0)

This error was detected while a MEX-file was running.  If the MEX-file
is not an official MathWorks function, please examine its source code
for errors.  Please consult the External Interfaces Guide for information
on debugging MEX-files.

If it is an official MathWorks function, please
follow these steps in reporting this problem to The MathWorks so
that we have the best chance of correcting it:

  1. Send this crash report to segv@mathworks.com for automated analysis.
     For your convenience, this information has been recorded in:
       C:\DOCUME~1\slp\LOCALS~1\Temp\matlab_crash_dump.2824

  2. Also, if the problem is reproducible, send the crash report to
     support@mathworks.com along with:
       - A specific list of steps that will reproduce the problem
       - Any M, MEX, MDL or other files required to reproduce the problem
       - Any error messages displayed to the command window
     A technical support engineer will contact you with further information.

Thank you for your assistance.  Please save your workspace and restart
MATLAB before continuing your work.


[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.305毫秒