From: us on 7 May 2010 15:32 "Todd Welti" <twelti(a)harman.com> wrote in message <hs1pap$91k$1(a)fred.mathworks.com>... > Is it possible to return a variable from a Matlab call to a perl script? > > I am not a per programmer, but tried adding > > return 0; > > to the end of the hello.pl examplt script (from Matlab documentation) and called it: > > a = perl('hello.pl','World') > > But I get error in perl.m > > ??? Error using ==> perl at 82 > System error: Can't return outside a subroutine at hello.pl line 7. > Hello World.Command executed: perl hello.pl World note: this NG deals with ML related problems... us
From: Ashish Uthama on 7 May 2010 15:35 On Fri, 07 May 2010 15:23:05 -0400, Todd Welti <twelti(a)harman.com> wrote: > Is it possible to return a variable from a Matlab call to a perl script? > > I am not a per programmer, but tried adding > > return 0; > > to the end of the hello.pl examplt script (from Matlab documentation) > and called it: > > a = perl('hello.pl','World') > > But I get error in perl.m > > ??? Error using ==> perl at 82 > System error: Can't return outside a subroutine at hello.pl line 7. > Hello World.Command executed: perl hello.pl World It appears that all output of the perl program to standard display is returned as a char array from the PERL MATLAB function call. What do you want returned from the perl script? (what is the value of the 'variable'?). You could just print it and then parse the text string in MATLAB.
From: Todd Welti on 7 May 2010 15:55 "Ashish Uthama" <first.last(a)mathworks.com> wrote in message <op.vccoo3eva5ziv5(a)uthamaa.dhcp.mathworks.com>... > On Fri, 07 May 2010 15:23:05 -0400, Todd Welti <twelti(a)harman.com> wrote: > > > Is it possible to return a variable from a Matlab call to a perl script? > > > > I am not a per programmer, but tried adding > > > > return 0; > > > > to the end of the hello.pl examplt script (from Matlab documentation) > > and called it: > > > > a = perl('hello.pl','World') > > > > But I get error in perl.m > > > > ??? Error using ==> perl at 82 > > System error: Can't return outside a subroutine at hello.pl line 7. > > Hello World.Command executed: perl hello.pl World > > It appears that all output of the perl program to standard display is > returned as a char array from the PERL MATLAB function call. > > What do you want returned from the perl script? (what is the value of the > 'variable'?). You could just print it and then parse the text string in > MATLAB. variable would be some formatted string i guess. Matalb help file says: "result = perl(...) returns the results of attempted Perl call to result." That would be nicer, but printing could work as well I guess. How do you parse the printed data back into the Matlab code that called the perls script, and would there be any problem if this was all compiled (it will be)?
From: Ashish Uthama on 7 May 2010 16:16 On Fri, 07 May 2010 15:55:21 -0400, Todd Welti <twelti(a)harman.com> wrote: Todd, I think the 'result' is essentially the standard output of the perl script. A plain print in the perl script dumps stuff on to the standard output. >> variable would be some formatted string i guess. Parsing would depend on the type of formating. Without any more info, I would say look at: TEXTSCAN, REGEXP, STRTOK, STRFIND, STRCMP ..etc.. hello.pl: $input = $ARGV[0]; print "Hello $input."; MATLAB command line: >> str=perl('hello.pl','World'); >> [tok str]=strtok(str); disp(tok); Hello >> [tok str]=strtok(str); disp(tok); World. Yes, I believe this can be compiled (the OS specific notes in the doc page will apply)
|
Pages: 1 Prev: returning variable from perl script Next: Removing rows containing all zeros in a matrix |