how I can transform syms to String in java?

1 view (last 30 days)
Im trying to make a calculator (for school) where i can integrate, derivative and graph an equation. But when matlab have to return the answer, i get a Exception, i was looking around until i found that matlab turn the answer to "syms" (54*x - 4 for example). So i try to get like an object then turning into string but all i got is " [Ljava.lang.Object;@4b9385". It is there anyway that i can get the syms and turning into a string?

Answers (1)

Walter Roberson
Walter Roberson on 18 Sep 2015
char() the syms object. For example,
syms x
result = diff(sin(x) - cosh(x),x);
result_string = char(result);
  2 Comments
Oscar Gutierrez
Oscar Gutierrez on 18 Sep 2015
that actually looks like it may work but im not sure how to implement it... it says i cant turn object into char, i try a couple of things i know but it wont work. Ill keep trying. Thanks for the help! these are a few thing i have try, if you think of something, please tell me :)
proxy.setVariable("ans", 5);
proxy.feval("syms", "x");
proxy.eval("a = int(9*x^3 - 2*x^2,2,x)");
Object[] d = proxy.returningEval("a", 0);
Character g;
g.getClass();
char ch[];
//g = new Character(d);
//String result1 = g.charValue(d);
//String result2 = char(d);
//String result3 = (char) d;
//String result4 = String.valueOf( proxy.getVariable("a"));
// String result5 = (Character)d;
System.out.println("Result: " + result1);
proxy.disconnect();
Walter Roberson
Walter Roberson on 18 Sep 2015
If I understand the examples, then
Object[] d = proxy.returningeval("char( int(9*x^3 - 2*x^2,2,x) )", 1);
System.out.println("Result: " + d[0]);
This is consistent with the "returning feval" example at https://code.google.com/p/matlabcontrol/wiki/Walkthrough which is a case that returns a string.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!