0

I have a matlab function, that calls a java function for displaying GUI.

function [] =  Start(x, y)    
    main.Main.main({x,y});   
end

I need to run clear java; command before calling the main function. To delete any data from the previous run.

But in doing so, the input variables x and y are also erased from the memory.

How can I ensure that the memory is clear before running the main function? (Running clear java; from the command line before calling Start(x,y) is not an option).

2 Answers 2

0

If x and y are defined in the base workspace then you could do something along these lines:

function [] = Start
    clear java
    x = evalin('caller', 'x');
    y = evalin('caller', 'y');
    main.Main.main({x,y});
end

However this is a horrible hack and not recommended!

Sign up to request clarification or add additional context in comments.

Comments

0
clear java

... clears the java class path, as well as variables in scope, it does not clear "java variables".

If you need to delete data from the previous run, you need to clear that data. If that data is in a Java object then you may need to clear any references to that object.

See http://www.mathworks.com.au/help/matlab/ref/clear.html for more info

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.