JuliaInterop / MATLAB.jl

Calling MATLAB in Julia through MATLAB Engine
MIT License
272 stars 64 forks source link

Question: Changing m-file has no effect. #39

Closed EricForgy closed 8 years ago

EricForgy commented 8 years ago

Hi,

I am doing some tests and have an m-file test.m. I am calling this with

mat"""
result = test();
"""
@mget result
println(result)

Everything works great. My result is extracted from Matlab into Julia and I can print it to the REPL, BUT if I change the m-file, the output is unchanged.

I guess this illustrates a misunderstanding on my part? I thought mat"..." simply called my Matlab function, but if that were the case, changes to test.m would be reflected in Julia, but changes are not being reflected. Why is that? Is there some way to have changes to the m-file reflected in Julia?

EricForgy commented 8 years ago

Here is a sample code that has me confused:

using MATLAB

function test()
    path = Pkg.dir("Coherent","src","matlab")
    println(path)
    mat"""
    cd($path)
    p = which('test');
    a = test(4,5);
    """
    @mget p
    println(p)
    @mget a
    println(a)
    txt = open(readall,p)
    println(txt)
end

test()

The output is:

julia> include(Pkg.dir("Coherent","src","matlab","matlab.jl"))
C:\Users\Eric Forgy\.julia\v0.4\Coherent\src\matlab
A MATLAB session is open successfully
C:\Users\Eric Forgy\.julia\v0.4\Coherent\src\matlab\test.m
[0.4034911431245899 0.3316652387426293 0.8841530577496601 0.04740146202915074 0.5449058982446715
 0.12202051825212956 0.15223401286294647 0.09427839006414607 0.3423735031607398 0.6862234629840409
 0.26843882139728314 0.34800765971611347 0.930040626107489 0.7359661588801641 0.8936326959336016
 0.2578461701126047 0.12165845430772615 0.3990199690345555 0.7946821573338052 0.054791789919732437]
function results = test(m,n)

% results.name = 'Test';
% results.a = rand(m,n);

results = 'Test';

Basically, I get the path of my m-file and print it to the REPL: looks good.

Then, I cd into that path from with mat"..." and try a which to make sure I am calling the correct test.m and store the path to a Matlab variable. I extract that variable to Julia and print it to the REPL: looks good.

Then, I run the Matlab test code and store the results to a variable and extract that variable from Matlab to Julia and print it to the REPL. not good. The results correspond an old version of test.m.

Then, to make sure there isn't something strange with my paths, etc., I actually read the m-file contents into Julia and print them to the REPL. Looks good. I can see the latest code.

But why isn't that code running and the old test is running. Is it getting compiled/cached somewhere? If so, how do I stop it from doing that? Clear the cache somehow? How?

Thanks!

Edit: The old test is getting called even if I completely shut down Julia and restart.

EricForgy commented 8 years ago

It's my fault, but I'm really in a bind and need to sort this out soon. Hope someone can help :sweat:

tkelman commented 8 years ago

I don't really know how this package works, but have you tried sending a clear all to matlab?

EricForgy commented 8 years ago

Thanks @tkelman !

My Matlab code is pretty big with a heavy initialization step and then I want to send light update requests from Julia. So clear all helps with the initialization step, but then when I later call update, I don't want to clear all again or I lose my initialization. But even if I clear all just in the initialization step, the update called after a clear all in the initialization step is still stale and doesn't recognize changes in the m-file. The only way I can get the update to recognize changes in my m-file is to reboot my computer. So there must be something saved somewhere :sweat:

ihnorton commented 8 years ago

How about rehash or rehash path?

EricForgy commented 8 years ago

Thanks @ihnorton. Will try :muscle:

We have a product demo and was saving this piece until last because I was "confident" it would work :sweat_smile:

ihnorton commented 8 years ago

Apparently this is possible from the Python engine driver (at least if you open the editor via the engine?): http://www.mathworks.com/help/matlab/matlab_external/call-user-script-and-function-from-python.html

EricForgy commented 8 years ago

Thanks @ihnorton . I just tried rehash and no luck.

I would be happy to learn I am doing something completely stupid if it got me a solution, but I am quite sure this is something with MATLAB.jl.

EricForgy commented 8 years ago

I think I was doing something completely stupid :)

EricForgy commented 8 years ago

Well, I certainly did do something stupid, but that problem is orthogonal to this issue. It remains that I need to restart my computer in order to have MATLAB.jl see my changes to the m-file.

EricForgy commented 8 years ago

My demo went "OK", but could not use MATLAB.jl. I doubt it is a problem with MATLAB.jl and it is probably just a problem with using Matlab via ActiveX. Conclusion. Matlab sucks :)