Tuesday, October 5, 2010

matlab eval 2 string linebreak to

So I wanted my Matlab eval input to be made into a string I could post on a website.
The evalc() Matlab function returns a character array, but I wanted a string I could send through a socket to a website.

I had an issue with finding the exact line break, I tried char(10) and '\n' but that did not work so I cheated. Here is my cheat:

function STR2=eval2str(msg)
STR=evalc(msg) %eval input
A=evalc('X=2') %eval to get character? char(10) and \n did not work for me?
STR=strrep(STR,' ','%') %I justed used this to temporarily replace the spaces

So if I input eval2str('X=rand(2,2)') I get a string like this:


Which is a string I can pass through my socket and then replace the % with ' ' on the otherside. So I can use Matlab to eval to a string output and send over a socket for a matlab server :).

No comments: