{"id":1086,"date":"2013-04-17T10:18:32","date_gmt":"2013-04-17T15:18:32","guid":{"rendered":"https:\/\/blogs.mathworks.com\/videos\/?p=1086"},"modified":"2013-04-22T08:01:04","modified_gmt":"2013-04-22T13:01:04","slug":"generalizing-the-access-to-an-array-of-structures-in-matlab","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/videos\/2013\/04\/17\/generalizing-the-access-to-an-array-of-structures-in-matlab\/","title":{"rendered":"Generalizing the access to an array of structures in MATLAB"},"content":{"rendered":"Recently a MATLAB user asked me how to make it possible to work with an array of structures in such a way that she could filter the array of structures and then combine the remaining fields.  Once combined she would run arbitrary processing functions on this combined data.\r\n<p>\r\nThis generalized architecture allows her to not use switch case and other flow control.  The strings that represent the fields of interest could come from a GUI making her GUI able to process in many arbitrary and customizable ways.\r\n<p>\r\n\r\n<div><div class=\"row\"><div class=\"col-xs-12 containing-block\"><div class=\"bc-outer-container add_margin_20\"><videoplayer><div class=\"video-js-container\"><video data-video-id=\"3877436965001\" data-video-category=\"blog\" data-autostart=\"false\" data-account=\"62009828001\" data-omniture-account=\"mathwgbl\" data-player=\"rJ9XCz2Sx\" data-embed=\"default\" id=\"mathworks-brightcove-player\" class=\"video-js\" controls><\/video><script src=\"\/\/players.brightcove.net\/62009828001\/rJ9XCz2Sx_default\/index.min.js\"><\/script><script>if (typeof(playerLoaded) === 'undefined') {var playerLoaded = false;}(function isVideojsDefined() {if (typeof(videojs) !== 'undefined') {videojs(\"mathworks-brightcove-player\").on('loadedmetadata', function() {playerLoaded = true;});} else {setTimeout(isVideojsDefined, 10);}})();<\/script><\/div><\/videoplayer><\/div><\/div><\/div>\r\n <\/div>\r\n\r\nHere is the code from the post:\r\n\r\n<code><pre>\r\nclear\r\nclc\r\n\r\ns(1).condition = 1;\r\ns(2).condition = 1;\r\ns(3).condition = 2;\r\ns(4).condition = 2;\r\n\r\ns(1).velocity = [11:21];\r\ns(2).velocity = [22:32];\r\ns(3).velocity = [33:43];\r\ns(4).velocity = [44:54];\r\n\r\ns(1).acceleration = [111:121];\r\ns(2).acceleration = [122:132];\r\ns(3).acceleration = [133:143];\r\ns(4).acceleration = [144:154];\r\n\r\nfieldToFilterBy    = 'condition';\r\nvalueToFilterBy    = 2;\r\nfieldToProcess     = 'acceleration';\r\nprocessingFunction = @mean;\r\n\r\n\r\nlistOfFilterValues    = [s.(fieldToFilterBy)];\r\nvi                    = (listOfFilterValues == valueToFilterBy)\r\nfilteredStructure     = s(vi)\r\nmergedFieldOfInterest = [filteredStructure(:).(fieldToProcess)]\r\nprocessedFilteredData = feval(processingFunction, mergedFieldOfInterest)\r\n<\/pre><\/code>","protected":false},"excerpt":{"rendered":"<div class=\"thumbnail thumbnail_asset asset_overlay video\"><a href=\"https:\/\/blogs.mathworks.com\/videos\/2013\/04\/17\/generalizing-the-access-to-an-array-of-structures-in-matlab\/?dir=autoplay\"><img decoding=\"async\" src=\"https:\/\/cf-images.us-east-1.prod.boltdns.net\/v1\/static\/62009828001\/c090f01e-30cd-4cbe-88b2-ceb7b2715668\/51faa1cc-9529-4c66-84c8-a8e6f20db612\/1280x720\/match\/image.jpg\" onError=\"this.style.display ='none';\"\/>\n      <div class=\"overlay_container\">\n      <span class=\"icon-video icon_color_null\"><time class=\"video_length\">6:53<\/time><\/span>\n      <\/div>\n      <\/a><\/div><p>Recently a MATLAB user asked me how to make it possible to work with an array of structures in such a way that she could filter the array of structures and then combine the remaining fields.  Once&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/videos\/2013\/04\/17\/generalizing-the-access-to-an-array-of-structures-in-matlab\/\">read more >><\/a><\/p>","protected":false},"author":68,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,12,20],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/posts\/1086"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/users\/68"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/comments?post=1086"}],"version-history":[{"count":5,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/posts\/1086\/revisions"}],"predecessor-version":[{"id":1098,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/posts\/1086\/revisions\/1098"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/media?parent=1086"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/categories?post=1086"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/tags?post=1086"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}