2013-07-11 35 views
3

我正在運行八度音階的matlab代碼。我猜,導入功能沒有在覈心八度中實現。任何想法如何在八度使用這個matlabe函數?八度導入函數

以下是我有: 倍頻3.4.0:7>設置 導入包: BRML * 警告:'進口」功能沒有在八度尚未實現

請閱讀`http://www.octave.org/missing.html '以瞭解如何爲 貢獻缺失的功能。

error:`import'undefined near line 8 column 5

+1

你可以將你的代碼發佈到你使用'import'函數的地方嗎? – am304

回答

4

你可以自己定製import.m。從http://octave.1599824.n4.nabble.com/namespace-support-td1638758.html

function import(varargin) 
error(nargchk(1, inf, nargin, "struct")); 
for i=1:nargin 
    [names, funcs] = import1(varargin{i}); 
    for j=1:length(names) 
    assignin("caller", names{j}, funcs{j}); 
    endfor 
endfor 
endfunction 

function [names, funcs] = import1(pkgname) 
pkgname_parts = strsplit(pkgname, "."); 
if length(pkgname_parts) > 2 
    error("invalid package name: %s", pkgname); 
endif 
pkgpath = locatepkg(pkgname_parts{1}); 
unwind_protect 
    cwd = pwd; 
    cd(pkgpath); 
    names = what(pwd); 
    names = {names.m{:}, names.mex{:}, names.oct{:}}; 
    names = cellfun(@stripExtension, names, "UniformOutput", false); 
    if length(pkgname_parts) == 2 
    if any(strcmp(pkgname_parts{2}, names)) 
     names = {pkgname_parts{2}}; 
    else 
     error("function `%s' not found in package `%s'", ... 
     pkgname_parts{2}, pkgname_parts{1}); 
    endif 
    endif 
    funcs = cellfun(@str2func, names, "UniformOutput", false); 
unwind_protect_cleanup 
    cd(cwd); 
end_unwind_protect 
endfunction 

function pkgpath = locatepkg(pkgname) 
pathdirs = strsplit(path, pathsep); 
for iPath=1:length(pathdirs) 
    pkgpath = [pathdirs{iPath} filesep "+" pkgname]; 
    if exist(pkgpath, "dir") 
    return; 
    endif 
endfor 
error("package `%s' cannot be located in the path", pkgname); 
endfunction 

function fileName = stripExtension(fileName) 
dotIndices = strfind(fileName, "."); 
fileName = fileName(1:(dotIndices(end)-1)); 
endfunction