I am running matlab code in octave. The import function is not implemented in core octave, I guess. Any idea how to use this matlabe function in octave?
Here is what I have: octave-3.4.0:7> setup Importing packages: brml.* warning: the `import' function is not yet implemented in Octave
Please read `http://www.octave.org/missing.html' to learn how you can contribute missing functionality.
error: `import' undefined near line 8 column 5
When Octave defines a function from a function file, it saves the full name of the file it read and the time stamp on the file. If the time stamp on the file changes, Octave may reload the file. When Octave is running interactively, time stamp checking normally happens at most once each time Octave prints the prompt.
The Import Tool lets you preview and import data from spreadsheet files, delimited text files, and fixed-width text files. You can interactively select the data to import and reuse the script or function that the tool generates to import other similar files.
data = load('-ascii','autocleaned. txt'); Loaded the data as wanted in to a matrix in Octave. Since all the data is in fixed width columns (except the last strings), you should be able to read it line by line, using fscanf to decode the line.
You can make your own custom import.m. From 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With