matlab - import function in octave -


i running matlab code in octave. import function not implemented in core octave, guess. idea how use matlabe function in octave?

here have: octave-3.4.0:7> setup importing packages: brml.* warning: `import' function not yet implemented in octave

please read `http://www.octave.org/missing.html' learn how can contribute missing functionality.

error: `import' undefined near line 8 column 5

you can make own custom import.m. http://octave.1599824.n4.nabble.com/namespace-support-td1638758.html:

function import(varargin)   error(nargchk(1, inf, nargin, "struct"));   i=1:nargin     [names, funcs] = import1(varargin{i});     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);   ipath=1:length(pathdirs)     pkgpath = [pathdirs{ipath} filesep "+" pkgname];     if exist(pkgpath, "dir")       return;     endif   endfor   error("package `%s' cannot located in path", pkgname);  endfunction   function filename = stripextension(filename)   dotindices = strfind(filename, ".");   filename = filename(1:(dotindices(end)-1));  endfunction  

Comments