More import help

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

More import help

Rik-4
I have some more code samples to run in Matlab for someone who has access.

Test #1:

Make a file myfunc.m with the following

--File myfunc.m--
function retval = myfunc ()
  retval = Map ('a', 1);
 
  import containers.Map
end
--End File--

At the command line, execute 'myfunc'.  Does it return a Map object, or
does it complain that Map does not exist?

Test #2:

--File myfunc2.m--
function retval = myfunc2 (flag)
  if (flag)
    import containers.Map
  end

  retval = Map ('a', 1);
end
--End File--

At the command line try

myfunc2 (0)
myfunc2 (1)

It is really awkward to support conditional imports, and Matlab itself
warns that you shouldn't do it, but I do wonder if it throws an error, a
warning, or just processes it somehow.

Thanks,
Rik


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: More import help

Burgers, A.R. (Teun)
Op 10-8-2017 om 1:33 schreef Rik:

> I have some more code samples to run in Matlab for someone who has access.
>
> Test #1:
>
> Make a file myfunc.m with the following
>
> --File myfunc.m--
> function retval = myfunc ()
>    retval = Map ('a', 1);
>  
>    import containers.Map
> end
> --End File--
>
> At the command line, execute 'myfunc'.  Does it return a Map object, or
> does it complain that Map does not exist?
>
> Test #2:
>
> --File myfunc2.m--
> function retval = myfunc2 (flag)
>    if (flag)
>      import containers.Map
>    end
>
>    retval = Map ('a', 1);
> end
> --End File--
>
> At the command line try
>
> myfunc2 (0)
> myfunc2 (1)
>
> It is really awkward to support conditional imports, and Matlab itself
> warns that you shouldn't do it, but I do wonder if it throws an error, a
> warning, or just processes it somehow.
>
> Thanks,
> Rik
>
>
>


 >> myfunc

ans =

   Map with properties:

         Count: 1
       KeyType: char
     ValueType: double

 >> myfunc2(0)

ans =

   Map with properties:

         Count: 1
       KeyType: char
     ValueType: double

 >> myfunc2(1)

ans =

   Map with properties:

         Count: 1
       KeyType: char
     ValueType: double


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: More import help

Richard Crozier
In reply to this post by Rik-4
On 10/08/17 00:33, Rik wrote:

> I have some more code samples to run in Matlab for someone who has access.
>
> Test #1:
>
> Make a file myfunc.m with the following
>
> --File myfunc.m--
> function retval = myfunc ()
>    retval = Map ('a', 1);
>  
>    import containers.Map
> end
> --End File--
>
> At the command line, execute 'myfunc'.  Does it return a Map object, or
> does it complain that Map does not exist?

R2016b

 >> myfunc

ans =

   Map with properties:

         Count: 1
       KeyType: char
     ValueType: double



> Test #2:
>
> --File myfunc2.m--
> function retval = myfunc2 (flag)
>    if (flag)
>      import containers.Map
>    end
>
>    retval = Map ('a', 1);
> end
> --End File--
>
> At the command line try
>
> myfunc2 (0)
> myfunc2 (1)

 >> myfunc2 (0)

ans =

   Map with properties:

         Count: 1
       KeyType: char
     ValueType: double

 >> myfunc2 (1)

ans =

   Map with properties:

         Count: 1
       KeyType: char
     ValueType: double



Regards,

Richard

--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.


Loading...