How do I use UIOPEN with custom file types in MATLAB 7.12 (R2011a)?

7 views (last 30 days)
I have a custom file type and a function for loading data that works in conjunction with MATLAB's OPEN. However, UIOPEN, which uses OPEN to access data in a file, doesn't return anything.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 2 Sep 2011
One possible method is to use ASSIGNIN, a function that allows one to assign variables to the base or a calling workspace. By placing ASSIGNIN inside the custom loading function, one can save variables to the base workspace when UIOPEN is called.
For example, imagine a EXT-file contained only a single number that should be stored to variable 'x'. The following implementation of OPENEXT would load that number and save it to the base workspace:
function data = openext(file)
%%Load the data
data = load(file,'-ascii');
%%Save to the workspace
if nargout == 0 % Don't save to the workspace if using the return variable
assignin('base','x',data);
end
When UIOPEN is used to open a EXT-file, UIOPEN will call OPEN. OPEN will in turn call OPENEXT, and OPENEXT will use ASSIGNIN to save the variable to the base workspace. The conditional statement is not necessary, but used to avoid saving variables if not necessary. Note that more complicated code could be used to change variable names and avoid overwriting existing variables. See the documentation for the EXIST function.
<http://www.mathworks.com/help/releases/R2011a/techdoc/ref/exist.html>
Note that by extending UIOPEN in this manner, one also extends the behavior of the MATLAB Desktop. One may double click files in the Current Folder window or drag and drop files over the command window. Both will ultimately call UIOPEN.

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Products


Release

R2011a

Community Treasure Hunt

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

Start Hunting!