|
Le He <flylehe@hotmail.com> wrote:
> Hi,
> in bash I like to pipe some expression to matlab:
> $ result=$(echo "3+3"|matlab)
> $ echo $result
> Warning: No display specified. You will not be able to display graphics
on the screen. < M A T L A B (R) > Copyright 1984-2008 The MathWorks, Inc.
Version 7.6.0.324 (R2008a) February 10, 2008 To get started, type one of
these: helpwin, helpdesk, or demo. For product information, visit
www.mathworks.com. Warning: Name is nonexistent or not a directory:
/matlab. > In path at 110 In startup at 4 In matlabrc at 272 Warning: Name
is nonexistent or not a directory: /toolbox. > In path at 110 In startup at
15 In matlabrc at 272 >> ans = 6 >>
>
> But I don't want the message and prompt in the result variable. So is
there any way to make result just store 6, e.e.
> $ echo $result
> 6
>
There are many ways. I am sure plenty are tidier than this one:
cow-lx 15% bash
bash-2.05b$ result=$(echo "disp(sprintf('\\n%0.6g',3+3)),quit" \
> | matlab -nodisplay -nojvm | tail -1)
bash-2.05b$ echo $result
6
bash-2.05b$ exit
exit
cow-lx 16%
Note that the backslash is to continue the command onto the next line, and
that the > on the next line is the prompt for me to continue.
I used disp(sprintf()) to get the answer on a line by itself.
--
Dr Tristram J. Scott
Energy Consultant
|