Output of matlab as a variable for shell script

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Output of matlab as a variable for shell script
# 8  
Old 09-17-2011
This is really frustrating, none of the above methods seem to work.

I tried ahamed101's three suggestions with the following result

cmd=`matlab -nodesktop -nosplash -nojvm -r "nc;quit" | awk -F"[ =]" '{print $NF}'`
echo $cmd
screen. > Inc. (glnxa64) 2010 demo. www.mathworks.com. 226

cmd=`matlab -nodesktop -nosplash -nojvm -r "nc;quit" | sed 's/.*= \([0-9]*\)$/\1/g'`
echo $cmd
Warning: No display specified. You will not be able to display graphics on the screen.  < M A T L A B (R) > Copyright 1984-2010 The MathWorks, Inc. Version (R2010a) 64-bit (glnxa64) February 5, 2010 To get started, type one of these: helpwin, helpdesk, or demo. For product information, visit www.mathworks.com. >> ans = 226

cmd=`matlab -nodesktop -nosplash -nojvm -r "nc;quit" | cut -d= -f2 | sed 's/ //g'`
echo $cmd
Warning:Nodisplayspecified.Youwillnotbeabletodisplaygraphicsonthescreen. <MATLAB(R)> Copyright1984-2010TheMathWorks,Inc. Version7.10.0.499(R2010a)64-bit(glnxa64) February5,2010 Togetstarted,typeoneofthese:helpwin,helpdesk,ordemo. Forproductinformation,visitwww.mathworks.com. >> 226

bartus11's last line gives a blank line again Smilie

---------- Post updated at 10:03 PM ---------- Previous update was at 09:58 PM ----------

ahamed101, How did you check if it worked? was it using matlab?
# 9  
Old 09-18-2011
Try this...
cmd=`matlab -nodesktop -nosplash -nojvm -r "nc;quit" | awk -F"[ =]" '/ans =/{print $NF}'`

Looks like it is on multiple lines


---------- Post updated at 09:32 PM ---------- Previous update was at 09:30 PM ----------

cmd=`matlab -nodesktop -nosplash -nojvm -r "nc;quit" | sed -n '/ans =/ s/ans = \([0-9]*\)$/\1/gp'`


Last edited by ahamed101; 09-18-2011 at 02:38 AM..
This User Gave Thanks to ahamed101 For This Post:
# 10  
Old 09-18-2011
If the matlab output is on multiple lines, then I think you should separate the assignment from the splitting.
That way, the shell will have done its job of stripping off the newlines before you extract the last chunk.

cmd=`matlab -nodesktop -nosplash -nojvm -r "nc;quit"`
cmd=`echo $cmd | awk '{ print $NF }'`
echo $cmd

This User Gave Thanks to durden_tyler For This Post:
# 11  
Old 09-18-2011
I've made some progress. tyler_durden's seems to work, but not with $NF. If I had $NF it still gives a blank line, but I manually tried different field numbers and found it was 43. So it now looks like,
cmd=`matlab -nodesktop -nosplash -nojvm -r "nc;quit"
cmd=`echo $cmd | awk '{print $43}'`
echo $cmd

This isn't obviously ideal as it may not always be 43. I guess the problem is I don't know exactly what the output from matlab is like.
# 12  
Old 09-18-2011
Can you post output of:
matlab -nodesktop -nosplash -nojvm -r "nc;quit" | cat -eT

# 13  
Old 09-18-2011
This is the output.

                                                                              < M A T L A B (R) >$
                                                                    Copyright 1984-2010 The MathWorks, Inc.$
                                                                  Version (R2010a) 64-bit (glnxa64)$
                                                                                February 5, 2010$
  To get started, type one of these: helpwin, helpdesk, or demo.$
  For product information, visit www.mathworks.com.$
>> $
ans =$

# 14  
Old 09-18-2011
Nice mess Smilie. Try this:
cmd=`matlab -nodesktop -nosplash -nojvm -r "nc;quit"  | cat -eT | perl -ln0e '/(\d+)\$\s+$/;print $1'`

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to use printf to output a shell variable path?

So I created two shell variables: COLUMN1_HEADING, COLUMN2_HEADING. They have values: COLUMN1_HEADING="John" COLUMN2_HEADING="123456789" How would I use printf to get it to print an output like this: $COLUMN1_HEADING\t$COLUMN2_HEADING\nJohn\t123456789\n Thanks! (3 Replies)
Discussion started by: steezuschrist96
3 Replies

2. UNIX for Dummies Questions & Answers

Shell equivalent of matlab fwrite function

I have some matlab code that sends the serial port elements of an array using matlab's fwrite function, e.g.: fwrite(s, , 'uchar'); What would be a unix shell equivalent? E.g., after successfully accessing the port using instructions here: Simple terminal serial port program for Linux/MacOSX... (3 Replies)
Discussion started by: darwin_886
3 Replies

3. Shell Programming and Scripting

Sending sqlplus output to a shell variable

I am trying to import a sqlplus output into a shell variable but it doesnt seem to be working. set -x export DEPENDENT_CR_NO=`sqlplus -s /nolog <<EOF conn username/passwd set heading off select dependency from custom_patches where patch_name='PATCH.zip'; exit; EOF` echo $DEPENDENT_CR_NO ... (2 Replies)
Discussion started by: beginer314
2 Replies

4. Shell Programming and Scripting

Output to shell variable

head -n 1 ~/.fvwm/config | grep -c "some-string" It's the output from grep I need to put into a shell variable. Also - I appreciate tips for other commands giving the same output. (2 Replies)
Discussion started by: Swepter
2 Replies

5. Shell Programming and Scripting

Running matlab script from within bash script

Hi guys, I'm new to scripting and I'm wondering if I can run a matlab script from within a bash script. Basically, at the minute I have a bash script which creates a file "bottfile.xyz" I then import "bottfile.xyz" into matlab using importdata('bottfile.xyz'). Then I just run the matlab... (0 Replies)
Discussion started by: jhunter87
0 Replies

6. Homework & Coursework Questions

Matlab help! Reading in a file with a variable filename

1. The problem statement, all variables and given/known data: I want to read in a file, and plot the data in matlab. However, I do not like hardwiring filenames into my codes, so I always give the user the option to specify what the filename is. I am pretty inexperienced with matlab, so I have no... (0 Replies)
Discussion started by: ds7202
0 Replies

7. Shell Programming and Scripting

Capturing output of procedure in variable in shell script

Hi guys I am calling one DB2 stored proc through unix. It is giving me below output. I want to capture the value 150 in one UNIX variable in shell script. Please let me know how I can achieve this. Thanks in advance Value of output parameters -------------------------- Parameter Name :... (5 Replies)
Discussion started by: vnimavat
5 Replies

8. Shell Programming and Scripting

How to give a variable output name in a shell script inside a for loop

Hi all I run my program prog.c in the following way : $ ./prog 1 > output.txt where 1 is a user defined initial value used by the program. But now I want to run it for many a thousand initial values, 1-1000, and store all the outputs in different files. Like $ ./prog 1... (1 Reply)
Discussion started by: alice06
1 Replies

9. Shell Programming and Scripting

sql output to shell variable

Hi I tried searching but I used to see , this has been answered may times. But I could not find. I am looking a SQLPLUS output to be assigned to shell variable. This is what I coded. ##/bin/ksh sqlplus dmishr/mishra#09@ps004d.world <<ENDOFSQL spool abc.log SET ECHO OFF NEWP... (4 Replies)
Discussion started by: dgmm
4 Replies

10. Shell Programming and Scripting

how to assign sql output data to shell script variable

Hi Guys ! I am new to unix and want to find out how we can make sql statement data to shell script variable? Any help/suggestion is greatly appreciated -Chandra (1 Reply)
Discussion started by: kattics
1 Replies
Login or Register to Ask a Question