{"id":164,"date":"2010-02-22T10:26:00","date_gmt":"2010-02-22T10:26:00","guid":{"rendered":"https:\/\/www.root42.de\/blog\/?p=164"},"modified":"2010-02-22T10:26:00","modified_gmt":"2010-02-22T10:26:00","slug":"how-to-duplicate-matlab-functionality","status":"publish","type":"post","link":"https:\/\/www.root42.de\/blog\/?p=164","title":{"rendered":"How to duplicate Matlab functionality"},"content":{"rendered":"<p>Since I am a total Matlab-n00b, I rather write a convoluted Python script instead of using the appropriate Matlab function. And here it is. A small script to compute the standard deviation of two vectors. I guess this would have been one Matlab command.<\/p>\n<div><\/div>\n<p><\/p>\n<pre><br \/>import sys                                                                                                                                                                                       <br \/>import scipy.io                                                                                                                                                                                  <br \/>import math                                                                                                                                                                                      <br \/>                                                                                                                                                                                                <br \/>def computeStdDev(file, vec1, vec2):                                                                                                                                                             <br \/>   data = scipy.io.loadmat(file, struct_as_record=True)                                                                                                                                         <br \/>   vector1 = data[vec1]                                                                                                                                                                         <br \/>   vector2 = data[vec2]                                                                                                                                                                         <br \/>   if len(vector1) != len(vector2):                                                                                                                                                             <br \/>       print \"Error: Vectors do not have matching lengths.\"                                                                                                                                     <br \/>       return                                                                                                                                                                                   <br \/>   diff = vector1                                                                                                                                                                               <br \/>   N = len(diff)                                                                                                                                                                                <br \/>                                                                                                                                                                                                <br \/>   for i in range(N):                                                                                                                                                                           <br \/>       diff[i] = vector1[i] - vector2[i]                                                                                                                                                        <br \/>                                                                                                                                                                                                <br \/>   mu = 0                                                                                                                                                                                       <br \/>   for val in diff:                                                                                                                                                                             <br \/>       mu = mu + val                                                                                                                                                                            <br \/>   mu = mu \/ float(N)                                                                                                                                                                           <br \/>                                                                                                                                                                                                <br \/>   sigma = 0                                                                                                                                                                                    <br \/>   for i in range(N):                                                                                                                                                                           <br \/>       sigma = sigma + (diff[i] - mu)**2                                                                                                                                                        <br \/>   sigma = math.sqrt(sigma \/ float(N))                                                                                                                                                          <br \/>                                                                                                                                                                                                <br \/>   print \"mu: %f\" % mu                                                                                                                                                                          <br \/>   print \"sigma: %f\" % sigma                                                                                                                                                                    <br \/>                                                                                                                                                                                                <br \/>if len(sys.argv) != 4:                                                                                                                                                                           <br \/>   print \"Usage: %s file vector1 vector2\" % sys.argv[0]                                                                                                                                         <br \/>   sys.exit(0)                                                                                                                                                                                  <br \/>                                                                                                                                                                                                <br \/>computeStdDev(sys.argv[1], sys.argv[2], sys.argv[3])                                                                                                                                             <br \/><br \/><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Since I am a total Matlab-n00b, I rather write a convoluted Python script instead of using the appropriate Matlab function. And here it is. A small script to compute the standard deviation of two vectors. I guess this would have been one Matlab command. import sys import scipy.io import math def computeStdDev(file, vec1, vec2): data &hellip; <a href=\"https:\/\/www.root42.de\/blog\/?p=164\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to duplicate Matlab functionality&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[103,15],"tags":[],"_links":{"self":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/164"}],"collection":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=164"}],"version-history":[{"count":0,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/164\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=164"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}