Thread Subject: Overloading the import statement

Subject: Overloading the import statement

From: Cygnine

Date: 9 Feb, 2010 16:16:02

Message: 1 of 1

I'd like to overload Matlab's built-in import statement. Let's say I write a function like so:

function[] = import(varargin)

if strcmpi(varargin{1}, '3')
  fprintf('Yay, I got a 3! \n');
else
  call_matlabs_builtin_import_using_nasty_evalin_statement
end

Now if save this function and put it in my path:
1.) matlab yells at me about overloading functions. Fine.
2.) I can run
  >> import 3
      from the command line and get the desired result

However, if I put the statement

import 3

into a script or a function, Matlab does some sneaky preprocessing that automatically checks the syntax of things after the import statement. It appears to do this in it's preprocessing optimization step, and it throws the error:

??? Error: File: blah.m Line: 3 Column: 8
Arguments to IMPORT must either end with ".*"
 or else specify a fully qualified class name: "3" fails this test.

(blah.m was the script file I created). Clearly Matlab is doing some error checking before running the code...and I'd like to make it stop.

Any ideas?

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
import Cygnine 9 Feb, 2010 11:26:53
overloading Cygnine 9 Feb, 2010 11:26:53
rssFeed for this Thread

Contact us at files@mathworks.com