数学建模社区-数学中国
标题:
求助:关于混合编程的错误,用mex编译就出现 - MATLAB 应用发布
[打印本页]
作者:
深叶子
时间:
2014-8-23 20:04
标题:
求助:关于混合编程的错误,用mex编译就出现 - MATLAB 应用发布
如何实现C语言与MATLAB接口,出现 E:\PROGRA~1\MATLAB\R2012\BIN\MEX.PL: Error: No file names given. .错误。
( I! C& u& G- _5 P
这该怎么解决啊?
6 ^# Y2 U2 c3 a1 K k
》mex-setup
, w' G8 T: m* g1 L- y f
Usage:
6 L4 c, n- ~9 f+ c6 D% r
MEX [option1 ... optionN] sourcefile1 [... sourcefileN]
% H8 z+ i: l4 U
[objectfile1 ... objectfileN] [libraryfile1 ... libraryfileN]
- h2 z5 m' y/ S3 y! m' o
% L+ e" {2 H8 ?4 Z6 S
Use the -help option for more information, or consult the MATLAB API Guide.
6 v8 G. T# \- _4 q: o0 e4 a
; _6 \4 B( T6 R: s- m# m
8 G$ A* Y5 \' z+ A Q
E:\PROGRA~1\MATLAB\R2012\BIN\MEX.PL: Error: No file names given.
+ R1 ~5 K6 a' _% n5 c
2 P7 G+ Y; J# `+ v) w" \" o
Undefined function or variable 'setup'.
作者:
madio
时间:
2014-8-23 22:12
编译文件的时候后面要加上需要编译的文件的名字,貌似就是这个问题。Undefined function or variable 'setup'是不是mex后面没有加一个空格,你改成mex -setup试试
作者:
madio
时间:
2014-8-23 22:13
网上找到这个总结的不错,你可以借鉴!
5 q/ s( z& y9 x. b
& p; P& K' c( Y# m+ Y
在matlab上使用libsvm工具箱使用错误及解决方法汇总
3 E) s% Y1 U% y; d
首先附上使用过程
# u% M. U/ o1 b; T. s
step1: 输入>>mex -setup
( Z# a6 |5 {. X# H
step2:
( L4 F8 D0 o: K# {5 M1 z+ F
Please choose yourcompiler for building external interface (MEX) files:
: X3 y+ H1 l; @
Would you like mex to locate installed compilers [y]/n? 是否让matlab自动检测编译器可以选y
3 a8 ^& D V1 O& O8 S
step3:
9 u3 N8 y% D3 s/ F
Select a compiler:
$ X/ z! q7 F* ?( R5 W( a
, }5 S F1 S" M
& r0 G( l8 g/ @ L! x
[1] Lcc-win32 C2.4.1 in E:\PROGRA~1\MATLAB\R2010a\sys\lcc
% S! d M7 t: w
[2] MicrosoftVisual C++ 2008 SP1 in e:\Program Files\Microsoft Visual Studio 9.0
. b+ e$ w7 R5 b' A! F
[3] MicrosoftVisual C++ 6.0 in E:\Program Files\Microsoft Visual Studio
: V( i( s; m) A9 D
[0] None
$ {3 H% V. E; K! q7 W, P
[1]matlab 自带的不能用 其他的如果有的话 就相应的选择就行
+ a6 c1 O7 b* F& s
我选择了 【2】
2 a9 p, k9 o+ G
step4:
" @# C( Z# j+ G; e9 N! M
Compiler: Microsoft Visual C++ 2008 SP1
( g+ D/ j8 M* J. I
Location:e:\Program Files\Microsoft Visual Studio 9.0
# j2 a; g% |( [9 ^# k h, v
Are thesecorrect [y]/n? 路径是否正确 是的就选y
- h- E4 }" U( o1 ]8 D7 g* \% l
如果没有自动检测出来依次的话step2就选【n】就可以,再顺着提示下来。
! x+ c1 T4 o! O( r3 j6 o
Step 5
7 q: p; a$ O5 I& `
Make
# o i: s6 n- o" [6 }' F# c* e
后面就是:
! A4 A4 O3 c3 E, k# {4 R9 _
load heart_scale.mat(此处无分号)
+ Z" ?) ]( U: s9 G2 X, \ t
train = heart_scale_inst;
3 t! B- }3 M* W, X
train_label=heart_scale_label;
j& T( N& z3 n8 l" q! J& s
test=train;
1 s" x/ D4 G: k/ d! z0 Q
test_label=train_label;
7 Z% i$ m' b0 m/ p- O
model=svmtrain(train_label,train,'-c 2 -g0.01');
- y% w2 q1 G8 Y' h( `) p
[predict_label,accuracy]=svmpredict(test_label,test,model);
+ T! i. s" g+ U3 Q6 I
1
( x9 f. y H+ `& o; ]
make这一步报错
/ m M: s! F6 {) B
Error using mex (line 206)
: v# D/ c. C, A& l
Unable to complete successfully.
' N1 w E |: w& }* U- Z
Error in make (line 1)
- w' Y. X6 ~2 m* q# b+ S6 E, n
% This make.m is for MATLAB and OCTAVE
) Z. o- `; ?. q7 E, F0 T
under Windows, Mac, and Unix
- @, q( l# {& r
在尝试了许多方法后,竟然是换了低版本的libsvm,搞定了~~~
% m, D# z) ?5 O) M! b: N$ }* n
, F6 w# a) k" S' ~
2 还有一个make这一步出现的错误3 Make时出错
; x3 S8 q! [2 c( ~9 b% d6 Q
Undefined function orvariable 'make'
9 D4 }2 I% a: Q. y7 O% p. e
解决方法为:
: G/ e/ K5 \/ y# S- w
设置matlab的path
- g" x5 v2 o! S0 {! Y
方法file->set path->set subpath(为什么要sub path因为只有这样才能将你要加的文件目录的子文件都加进去,否则只是加了你所要加的那个目录。)
+ h( S- n L! A; j: y/ m& V3 G
还要记得把current folder 设为matlab所在的路径
/ C( q. h' I3 \! M8 z
3 输入load heart_scale.mat;报错
7 x8 j8 b1 A7 }5 A" g
Error using load
, l) s5 b3 S* b7 ~. U, t2 R
Unable to read file heart_scale.mat;: No
) Y* s0 h0 R& \5 K- @
such file or directory.
+ h: N* V: n+ R8 |2 _! ~
这个问题是这样的,不应该有最后那个; 去掉分号就可以了。。。(粗心所致。。。不知道别人会不会像我这样。。。)
/ P; g; x8 X* C2 k$ r" ^6 ?
4
4 Y- @3 E& Y2 h+ ?
load 这一步报错
' d6 V' p- m4 ?# d
??? Error using ==>load
8 I! t6 g: P2 j) `* Y c
Number of columns on line 2 of ASCII file D:\Program
9 r' \" D. L) z! R
Files\MATLAB2010\matlab\toolbox\libsvm-3.13\heart_scale
% L3 `( I9 n, a- Q. q
must be the same as previous lines.
) a# Y3 ~" N a& p
官方现在不给heart_scale.mat,给的都是VC++下的格式。一些旧版本的工具箱还可以找到mat文件,新版本都没有了。所以load会报错:heart_scalemust be same as previous lines)
% k. l3 ]! t- _# Q+ B7 f
一种解决方法是:使用给的一个函数,转化数据。此函数为libsvmread()
- t1 E# t& V% H" u5 T0 K7 T$ t
使用如下: [label_vector, instance_matrix] =libsvmread('filename');
+ A5 Q m+ i9 [+ q2 L
此处为了跟官方统一名称可以[heart_scale_label,heart_scale_inst] =libsvmread('heart_scale');
2 h( l; h- P. t
注意:由于heart_scale在libsvm-3.11目录下,不是在matlab下,所以直接用libsvmread命令会报错,要买改变当前路径,或者使用[heart_scale_label,heart_scale_inst]=libsvmread('../heart_scale');../代表返回上层路径。
2 b1 A4 }' T i @# @% J& N
但是最简单的方法是,找到旧版本工具箱的mat文件添加上即可!
" O, k" J3 N8 t" e6 \# E% O5 W
& l( W" [6 U! @( J
- _, R* J: b5 q( _ o* w% V
+ j' ]% J, L8 {7 X4 w7 [1 m8 L, k
, B+ n9 i' q' P" e! K- ~% W
5 到svmtrain这一步报错
8 w5 ^+ b0 d+ s
??? Errorusing ==>svmtrain at 172
' s( q2 d7 y0 C* w: k$ E$ }
Group mustbe a vector.
! ~7 b9 p4 c) R: K) [& [
是因为在添加工具箱的时候没有添加完全,file-Set Path-Add with Subfold ...添加好路径就可以了
$ m, c$ k1 a' F6 z, \2 K8 o
在使用过程中到目前只遇到这些错误~现在也只是会简单的用libsvm工具箱……
欢迎光临 数学建模社区-数学中国 (http://www.madio.net/)
Powered by Discuz! X2.5