Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Failed to get variable ans" error, when not trying to get ans. #174

Open
DNF2 opened this issue Aug 22, 2020 · 1 comment
Open

"Failed to get variable ans" error, when not trying to get ans. #174

DNF2 opened this issue Aug 22, 2020 · 1 comment

Comments

@DNF2
Copy link

DNF2 commented Aug 22, 2020

Using the string macro mat"" I frequently get "failed to get variable ans from MATLAB session" error. This happens even though I am suppressing Matlab output with ;. It happens in various situations, but this is the first reliably reproducible example I have been able to make:

Put this in a file Foo.m somewhere in your path:

classdef Foo < dynamicprops
end

Then run:

julia> using MATLAB

julia> mat"f = Foo();"
inary

julia> mat"addprop(f, 'bar');"
Error using save
Unable to save variable 'ans' of class 'meta.DynamicProperty' to STDIO.
 
ERROR: MATLAB.MEngineError("failed to get variable ans from MATLAB session")
Stacktrace:
 [1] get_mvariable(::MSession, ::Symbol) at /home/DNF/.julia/packages/MATLAB/cVrxc/src/engine.jl:164
 [2] get_mvariable at /home/DNF/.julia/packages/MATLAB/cVrxc/src/engine.jl:168 [inlined]
 [3] get_variable(::Symbol) at /home/DNF/.julia/packages/MATLAB/cVrxc/src/engine.jl:170
 [4] top-level scope at /home/DNF/.julia/packages/MATLAB/cVrxc/src/matstr.jl:169
 [5] include_string(::Function, ::Module, ::String, ::String) at ./loading.jl:1088
  • The dynamic property 'bar' is successfully created.
  • Why is the word 'inary' printed to output after creation of the object? This happens a lot.

MATLAB.jl v0.7.3
MATLAB Version: 9.8.0.1417392 (R2020a) Update 4

julia> versioninfo()
Julia Version 1.5.0
Commit 96786e22cc (2020-08-01 23:44 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-10875H CPU @ 2.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, skylake)
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 10
@DNF2
Copy link
Author

DNF2 commented Aug 23, 2020

Update: This seems to be a general issue for handle classes, whenever a method or function returns the object itself. Here's (possibly) minimal example:

Foo.m:

classdef Foo < handle
end

The error occurs when we don't capture the returned object:

julia> mat"f = Foo();"   # This is ok

julia> mat"Foo();"  # This is not ok
inary
Error using save
Unable to save variable 'ans' of class 'Foo' to STDIO.
 
ERROR: MATLAB.MEngineError("failed to get variable ans from MATLAB session")
Stacktrace:
 [1] get_mvariable(::MSession, ::Symbol) at /home/DNF/.julia/packages/MATLAB/cVrxc/src/engine.jl:164
 [2] get_mvariable at /home/DNF/.julia/packages/MATLAB/cVrxc/src/engine.jl:168 [inlined]
 [3] get_variable(::Symbol) at /home/DNF/.julia/packages/MATLAB/cVrxc/src/engine.jl:170
 [4] top-level scope at /home/DNF/.julia/packages/MATLAB/cVrxc/src/matstr.jl:169
 [5] include_string(::Function, ::Module, ::String, ::String) at ./loading.jl:1088

This doesn't work either:

julia> mat"Foo();";  # note the extra ; 

At least there is a workaround: capture the output in a variable. But what's up with the 'inary' ouput?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant