summaryrefslogtreecommitdiff
path: root/code/glue/extract-matlab-matrix
diff options
context:
space:
mode:
Diffstat (limited to 'code/glue/extract-matlab-matrix')
-rwxr-xr-xcode/glue/extract-matlab-matrix43
1 files changed, 43 insertions, 0 deletions
diff --git a/code/glue/extract-matlab-matrix b/code/glue/extract-matlab-matrix
new file mode 100755
index 0000000..b5021a4
--- /dev/null
+++ b/code/glue/extract-matlab-matrix
@@ -0,0 +1,43 @@
+#!/bin/bash
+
+# TODO: use tail instead of cat where only the top of the file is needed
+
+# extract the multiplier of the matrix
+MUL=`cat $1 \
+| egrep -o 'e\+[0-9]* \*' \
+| tr -d 'e+ *'`
+
+if [ -z "$MUL" ]; then
+ MUL=1
+fi
+
+# get the number of cols
+COLS=`cat $1 \
+| egrep '([:space:]*([01](\.[0-9]*){0,1})[:space:]*)+$' \
+| tail -n1 \
+| wc -w`
+
+# read the matrix, multiply to correct value and put it out
+cat $1 \
+| egrep '([:space:]*([01](\.[0-9]*){0,1})[:space:]*)+$' \
+| tr " " "\n" \
+| egrep -v '^$' \
+| while read; do
+ echo $MUL '*' $REPLY
+done \
+| bc \
+| sed 's/\([0-9]\+\)\.0*/\1/' \
+| ( I=1
+ while read; do
+ if [ $I -eq $COLS ]; then
+ echo "$REPLY"
+ I=1
+ else
+ echo -n "$REPLY,"
+ I=$(( $I + 1 ))
+ fi
+ done )
+
+
+# old debug stuff
+#echo $MUL $COLS \ No newline at end of file
contact: Jan Huwald // Impressum