{"id":390,"date":"2009-09-08T15:27:00","date_gmt":"2009-09-08T15:27:00","guid":{"rendered":"https:\/\/blogs.mathworks.com\/videos\/2009\/09\/08\/integrating-to-find-the-volume-underneath-a-set-of-nonuniformly-spaced-data\/"},"modified":"2009-09-18T16:21:27","modified_gmt":"2009-09-18T16:21:27","slug":"integrating-to-find-the-volume-underneath-a-set-of-nonuniformly-spaced-data","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/videos\/2009\/09\/08\/integrating-to-find-the-volume-underneath-a-set-of-nonuniformly-spaced-data\/","title":{"rendered":"Integrating to find the volume underneath a set of nonuniformly spaced data"},"content":{"rendered":"This video covers the use of GRIDDATA, anonymous functions, and QUAD2D to integrate the volume under a set of randomly spaced data points.  First an interpolation scheme must be put in place, then a numeric quadrature function is invoked.\r\n\r\nThis video shows the creation of a good synthetic data set with a known volume to test the rest of the algorithm.  A good test data set like this really give confidence in the building of your algorithm.\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=\"3877437981001\" 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 that was written:\r\n\r\n\r\n<pre>\r\n<code>% I have a dataset \"A\" (n by 3) of ordered triplets [x,y,z]. \r\n%I want to calculate the volume between surface defined by \"A\" and \r\n%the xy plane. \"A\" has only positive values but is not uniformly \r\n%spaced and not gridded. \"A\" cannot be described by a simple \r\n%function. Any help?\r\n\r\nn = 10;\r\nrandOffset = 0.1;\r\nh = 1;\r\n\r\nx = rand(n);\r\nx(1:4)=[0 1 0 1]';\r\ny = rand(n);\r\ny(1:4)=[0 0 1 1]';\r\nz = h + randOffset*rand(n) - randOffset\/2; %make average height\r\n\r\n\r\nplot3(x,y,z,'.')\r\naxis equal\r\nzlim([0 h + randOffset])\r\n\r\ninterpZ = @(xi,yi) griddata(x,y,z,xi,yi) %set up interpolation\r\n\r\ninterpZ(0.5,0.5) %test interpolation\r\nvol = quad2d(interpZ,0,1,0,1) %volume should be close to 1<\/code>\r\n<\/pre>\r\n\r\nNote: there is an update to this post here:\r\n\r\n<a href=\"https:\/\/blogs.mathworks.com\/videos\/2009\/09\/18\/revisited-integrating-to-find-the-volume-underneath-a-set-of-non-uniformly-spaced-data\/\">https:\/\/blogs.mathworks.com\/videos\/2009\/09\/18\/revisited-integrating-to-find-the-volume-underneath-a-set-of-non-uniformly-spaced-data\/<\/a>","protected":false},"excerpt":{"rendered":"<div class=\"thumbnail thumbnail_asset asset_overlay video\"><a href=\"https:\/\/blogs.mathworks.com\/videos\/2009\/09\/08\/integrating-to-find-the-volume-underneath-a-set-of-nonuniformly-spaced-data\/?dir=autoplay\"><img decoding=\"async\" src=\"https:\/\/cf-images.us-east-1.prod.boltdns.net\/v1\/static\/62009828001\/76f1e06a-90df-400a-bf69-f568c146203b\/572683bf-27e3-4e17-bf71-093138d795f1\/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\">5:50<\/time><\/span>\n      <\/div>\n      <\/a><\/div><p>This video covers the use of GRIDDATA, anonymous functions, and QUAD2D to integrate the volume under a set of randomly spaced data points.  First an interpolation scheme must be put in place, then a&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/videos\/2009\/09\/08\/integrating-to-find-the-volume-underneath-a-set-of-nonuniformly-spaced-data\/\">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,17,20],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/posts\/390"}],"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=390"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/posts\/390\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/media?parent=390"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/categories?post=390"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/tags?post=390"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}