How to import files in a function or script with the changed 'import' functionality in R2016b
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 15 de Nov. de 2016
Respondida: MathWorks Support Team
el 18 de Nov. de 2016
How to make the imported files available to the calling function/script in R2016b.
Respuesta aceptada
MathWorks Support Team
el 15 de Nov. de 2016
There has been changes made to the import functionality in R2016b release.
R2016b onwards the import function only affects the import list of the function or script within which it is used starting R2016b. If files have been imported in a script and that script has been called from another function then the imported files will not be available to the calling function. The change has been implemented because now function declarations can be added to a script, which was not available in previous versions. In previous versions a file could either be a script or a function but from MATLAB R2016b they can be used in a same file. Please use the following link to look at the release notes for MATLAB R2016b: <https://www.mathworks.com/help/matlab/release-notes.html?searchHighlight=calling%20import%20from%20script Release Notes>
To work around this issue please use either of the following approaches:
1. Replicate the set of import statements in each of the functions or scripts in your code. However, it might become tedious to replicate if there are large number of files to be imported.
2. The other alternative is to create a function where you can create a cell array of the strings of import statements to be included in the function or scripts files. Then you can invoke this function from the respective location and use the 'eval' function to execute the import statements. To understand this better, please refer to the code snippet below:
The new function file can be as follows:
>> function out = importJavaFiles()
>> count =0;
>> count= count+1;
>> out{count} = 'import com.bose.mdaq.*';
>> end
Then you can invoke this function from the respective script or function file as follows:
out = importJava();
for j=1:length(out)
eval(out{j});
end
This will include the expected files in the function or script from which it is being invoked.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre String Parsing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!