Hi,
it seems that the current symbolic toolbox has does not have
something like the matlab char() function. I have written a small
patch to the symbolic toolbox which adds a to_char() function by
which one can convert an expression to char. Would be nice if this or
something similar would be included into the symbolic toolbox, or
even better, if the char() function would be overloaded (no clue
whether this is possible in octave, I am not too familiar with
octave), so that one can run standard matlab code on it, i.e. that
char(1) would return '1' and char(x) would return 'x' when x=sym
('x'); etc.
Thanks
Nils
Here is the patch:
diff -upr symbolic-1.0.5/PKG_ADD symbolic-1.0.5-nils/PKG_ADD
--- symbolic-1.0.5/PKG_ADD 2008-02-16 10:14:34.000000000 +0000
+++ symbolic-1.0.5-nils/PKG_ADD 2008-03-06 14:51:56.000000000 +0000
@@ -3,6 +3,7 @@ autoload ("sym", fullfile (fileparts (mf
autoload ("is_vpa", fullfile (fileparts (mfilename ("fullpath")),
"symbols.oct"));
autoload ("is_sym", fullfile (fileparts (mfilename ("fullpath")),
"symbols.oct"));
autoload ("is_ex", fullfile (fileparts (mfilename ("fullpath")),
"symbols.oct"));
+autoload ("to_char", fullfile (fileparts (mfilename ("fullpath")),
"symbols.oct"));
autoload ("to_double", fullfile (fileparts (mfilename
("fullpath")), "symbols.oct"));
autoload ("digits", fullfile (fileparts (mfilename ("fullpath")),
"symbols.oct"));
autoload ("Cos", fullfile (fileparts (mfilename ("fullpath")),
"symbols.oct"));
diff -upr symbolic-1.0.5/src/symbols.cc symbolic-1.0.5-nils/src/
symbols.cc
--- symbolic-1.0.5/src/symbols.cc 2008-02-16 10:14:34.000000000
+0000
+++ symbolic-1.0.5-nils/src/symbols.cc 2008-03-06 15:42:40.000000000
+0000
@@ -39,6 +39,8 @@ along with this program; If not, see <ht
#include "ov-relational.h"
#include "sym-ops.h"
#include "symbols.h"
+#include <string>
+#include <sstream>
bool get_expression(const octave_value arg, GiNaC::ex& expression)
{
@@ -66,6 +68,18 @@ bool get_expression(const octave_value a
return true;
}
+
+
+bool get_char(const octave_value arg, std::string& str)
+{
+ GiNaC::ex ex;
+ if (!get_expression(arg, ex))
+ return false;
+ std::stringstream strstr;
+ strstr << GiNaC::dflt << ex;
+ str = strstr.str();
+ return true;
+}
bool get_symbol(const octave_value arg, GiNaC::ex& sym)
{
@@ -155,6 +169,47 @@ DEFUN_DLD(symbols,args,,"Initialize symb
return retval;
}
+DEFUN_DLD(to_char,args, ,
+"-*- texinfo -*-\n\
[EMAIL PROTECTED] {Loadable Function} {d =} to_char(@var{n})\n\
+\n\
+Convert a vpa, string, ex or string type to a string.\n\
+\n\
[EMAIL PROTECTED] deftypefn\n\
+")
+{
+ octave_value retval;
+ int nargin = args.length();
+ std::string str;
+
+ if (nargin != 1)
+ {
+ print_usage ();
+ return retval;
+ }
+
+ try
+ {
+ if (!get_char (args(0), str))
+ {
+ print_usage ();
+ return retval;
+ }
+ // charMatrix ch(1,str.size());
+ // ch.insert (str.c_str(), 0, 0);
+ retval = octave_value(str);
+ }
+ catch (std::exception &e)
+ {
+ error (e.what ());
+ retval = octave_value ();
+ }
+
+ return retval;
+}
+
+
+
DEFUN_DLD(to_double,args, ,
"-*- texinfo -*-\n\
@deftypefn {Loadable Function} {d =} to_double(@var{n})\n\
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Octave-dev mailing list
Octave-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/octave-dev