[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to pass variables from octave script to Ubuntu shell
From: |
Sebastian Döring |
Subject: |
Re: How to pass variables from octave script to Ubuntu shell |
Date: |
Mon, 30 Jan 2012 13:00:29 +0100 |
I think the problem with this solution is that my octave script consists of a function containing several commands.
Code looks like this:
function threshold(pfa)
printf("\n")
p_fa=str2double(pfa) # convert pfa, print it
iq_samples=read_complex_binary('noise.dat'); # read IQ samples
mag_squared=(abs(fft(iq_samples))).^2; # perform fft and calculate squared magnitude
var_est=sum(mag_squared)/length(mag_squared) # calculate estimated noise variance
lambda_fa=var_est*(1+(qfuncinv(p_fa))/(sqrt(length(mag_squared))/2)) # calculation of the threshold depending on var_est and p_fa
printf("\n")
endfunction
The parameter pfa is being passed by the bash script.
I want the last variable ("lambda_fa") to get passed back to the shell...
-Sebastian
2012/1/30 Carlo de Falco
<address@hidden>
2012/1/30 Sebastian Döring <address@hidden>:
> Hello list,
>
> I am using a bash script to execute several other scripts including an
> octave script.
> The bash script simply calls the octave script with the following
> command: "octave --silent --eval "myfile(\"$variable\")".
>
> My problem is now, that I want the octave script to return a certain
> variable it has calculated during its execution, back to the shell, so that
> I can use it further and pass it again to another script (e.g. python).
>
> I have searched google a lot about this and have also found a topic from
> this very mailing list (about "setenv"/"getenv"), but I don really seem to
> get it right.
>
> I would really appreciate if someone gave me a hint on how to use these
> commands, or maybe how to solve my problem in another way.
>
>
> Thanks in advance.
>
> -Sebastian
if you need to pass only one variable back to the shell you could
probably do something like
#!/bin/bash
res=$(octave -q --eval "y = quad (@sin, 0, pi); printf ('%5.5g', y)")
echo "the result is ${res}"
HTH,
c.