-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpython.m
More file actions
30 lines (28 loc) · 890 Bytes
/
python.m
File metadata and controls
30 lines (28 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function [result,status] = python(varargin)
% [result,status] = python('1.py','hui.py 1 dem2')
% call python
%命令字符串
cmdString='C:\Python26\ArcGIS10.0\python.exe';
for i = 1:nargin
thisArg = varargin{i};
if isempty(thisArg) || ~ischar(thisArg)
error(['All input arguments must be valid strings.']);
elseif exist(thisArg)==2
%这是一个在Matlab路径中的可用的文件
if isempty(dir(thisArg))
%得到完整路径
thisArg = which(thisArg);
end
elseif i==1
% 第一个参数是Python文件 - 必须是一个可用的文件
error(['Unable to find Python file: ', thisArg]);
end
% 如果thisArg中有空格,就用双引号把它括起来
if any(thisArg == ' ')
thisArg = ['"', thisArg, '"'];
end
% 将thisArg加在cmdString后面
cmdString = [cmdString, ' ', thisArg];
end
%发送命令
[status,result]=system(cmdString);