Posts

Showing posts from 2011

Microsoft Word to Matlab Matrix Conversion

I type in tons of equations in papers in MS Word (yeah, I need to learn LaTex). So when I have matrices in MS Word, you can't paste into Matlab because the MS Word format is funky. The perlie below will take care of it. Now I need to figure out a way to have it monitor the clipboard and automatically convert it if it detects a MSW matrix:


#echo Part is Microsoft Word Equation: echo "■(1&0&0@1&-4&2@1&2&-4)"|perl -lne 's/\&/ /g;s/\@/;/g;s/\(/\[/g;s/\)/\]/g;print "A = $1" if m/(\[.+\])/g' # Matlab Format: A = [1 0 0;1 -4 2;1 2 -4] And I decided to make it bidirectional (goes from Matlab to MS Word and vice versa). Pretty awesome...saving me tons of time:
#!/usr/bin/perl use strict; use warnings; print "\n"; my $bit = 0; my @global; while(<>){ if(m/\@|\&/){ &to_matlab($_); }else{ if(m/ans =/g){ $bit = 1; } if( $bit == 1 && $_ =~ m/\s+((-|\d*)\d+\.*\d*)/g){ push(@global,$1); }else{ …

New Blog

Renaissance Engineer.