Importing classes in scripts vs functions

5 views (last 30 days)
Andrew
Andrew on 25 Apr 2014
Edited: Andrew on 25 Apr 2014
I have a class file called auxFunctions.m, where several functions have been defined. When I import and call functions in the class file using the following syntax it works well:
import auxFunctions.*
[jointStruct,markerPlateStruct]=readInputSetupFile(setupFile);
However, when I try to do the same thing in a function that is called from another function I get this error:
Undefined function 'readInputSetupFile' for input arguments of type 'char'.
I put a break point on the the line that gives the error did the following K>> help readInputSetupFile readInputSetupFile
[jointStruct,markerPlateStruct]=readInputSetupFile(setupFileName) reads
the XML setup file ... (more details)
so it knows the function is there, however I cannot call it without putting auxFunctions.readInputSetupFile(setupFile).
I call many auxilary functions from this file and would like to use the short function calls, but I could not figure out how to make it work inside a nested function (it works in a script or in the main function). Does anyone know how I could do this, or do I just have to add in the auxFunctions.readInputSetupFile where ever I call the function?
Thank you!
  4 Comments
Sean de Wolski
Sean de Wolski on 25 Apr 2014
Do you then try to use it inside of a conditional?
I guess does the simplest possible function work?
function foo
import
call imported
end
Importing is local to functions and to control statements which is why I ask:
Andrew
Andrew on 25 Apr 2014
Edited: Andrew on 25 Apr 2014
I wrote a simple function to demonstrate the issue:
This does not work:
function [jointStruct,markerPlateStruct]=testClassImport
import auxFunctions.*
[jointStruct,markerPlateStruct]=readInputSetupFile('test_file.xml');
However if I do
import auxFunctions.*
[jointStruct,markerPlateStruct]=readInputSetupFile('test_file.xml');
in the command line or in a script, then it works.

Sign in to comment.

Answers (0)

Categories

Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!