{"id":10215,"date":"2025-11-21T14:42:53","date_gmt":"2025-11-21T19:42:53","guid":{"rendered":"https:\/\/blogs.mathworks.com\/community\/?p=10215"},"modified":"2025-11-21T14:42:53","modified_gmt":"2025-11-21T19:42:53","slug":"interpolation-games-with-matlab-copilot","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/community\/2025\/11\/21\/interpolation-games-with-matlab-copilot\/","title":{"rendered":"Interpolation Games with MATLAB Copilot"},"content":{"rendered":"<p>You may have seen the <a href=\"https:\/\/blogs.mathworks.com\/matlab\/2025\/11\/13\/matlab-copilot-gets-a-new-llm-november-2025-updates\/\">news on the MATLAB Blog<\/a> that MATLAB Copilot has been updated to the GPT-5 mini model. My experience has shown this to be a huge improvement. So if you haven't tried Copilot yet, now's the time! It's only getting better. And it's nice to know that you don't have to wait for the next general release of MATLAB to get this improved version of Copilot. It's a service that gets better for everyone across the board. MATLAB is improving while you sleep!<\/p>\n<p>I wanted to flex the latest Copilot, and an old problem came to mind that I remember from the Ancient Days: scattered data interpolation. Let's say I'm trying to make a 3D map of a mountain range. You've given me a list of measurements: altitudes for specific latitudes and longitudes, but in no particular order. What does the mountain range look like? This used to mean writing some non-trivial code, but about a dozen years ago we added the <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/scatteredinterpolant.html\">scatteredInterpolant<\/a> function to MATLAB and life got easier. This built-in function makes the scattered data interpolation problem go away. But now it's even easier than that! I don't have to read the doc or even know that the function exists. I just go to Copilot and enter something like this.<\/p>\n<pre>Across a 2D domain, I have a set of randomly scattered measurements of \r\naltitude points. That is, for a list of (x,y) tuples, I know z. \r\nHelp me turn this into a regularly sampled surface.<\/pre>\n<p>For my list of measurements, I'll be using random samples from a 3D surface. See if you can guess what it is!<\/p>\n<pre>% Determine the target shape. Choose mode number from k = 1..8.\r\nk = 1;\r\nm = 40;\r\nL = membrane(k,m);\r\n\r\n% Get random measurements across the surface\r\nnpts = 100;\r\nix = unique(randi(numel(L),[npts,1]));\r\n[y,x] = ind2sub([n,n],ix);\r\nz = L(ix);\r\n<\/pre>\n<p>Here are my measurements. With only 100 points, can you see the shape?<\/p>\n<pre>plot3(x,y,z,'.') \r\naxis vis3d<\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"250\" height=\"215\" class=\"alignnone size-full wp-image-10217\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/membrane_samples.png\" alt=\"\" \/><\/p>\n<p>Let's animate it to make it pop a little better.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"573\" height=\"473\" class=\"alignnone size-full wp-image-10225\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/anim.gif\" alt=\"\" \/><\/p>\n<p>So let's make an interpolated shape. This next part is the code that Copilot gave me.<\/p>\n<pre>% Given column vectors x, y, z (all same length)\r\n% Choose grid resolution\r\nn = size(L,1);\r\n\r\n% Grid covering the data range\r\nxqv = linspace(min(x), max(x), n);\r\nyqv = linspace(min(y), max(y), n);\r\n[Xq, Yq] = meshgrid(xqv, yqv);\r\n\r\n% Interpolate using scatteredInterpolant\r\nF = scatteredInterpolant(x, y, z, 'natural');\r\nZq = F(Xq, Yq);\r\n\r\n% Plot as surface (or use contourf\/imagesc)\r\nsurf(Xq, Yq, Zq)\r\naxis vis3d\r\n<\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"500\" height=\"531\" class=\"alignnone size-full wp-image-10219\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/Snag_f82bf4a.png\" alt=\"\" \/><\/p>\n<p>And there you have it! A slightly lumpy but recognizable reconstruction of the MathWorks logo (the output of membrane(1)) based on 100 randomly sampled points. Copilot made short work of my problem, giving me exactly what I was after. But all this playing around with scattered interpolants has made me hungrier for more. I'm curious how many points I need in order to see a particular shape.<\/p>\n<h3>An Interpolation Game<\/h3>\n<p>Let's make a game inside a MATLAB app. For this, I'm going to switch gears. Since this is a more complex task, I want to use one of our new prompts and the MATLAB MCP server that can be installed with Claude Desktop (<a href=\"https:\/\/blogs.mathworks.com\/matlab\/2025\/11\/03\/exploring-the-matlab-model-context-protocol-mcp-core-server-with-claude-desktop\/\">Learn more about how to set this up from Mike's blog<\/a>). Having access to this server makes everything go much faster. Here's a sketch of the app interface I want Claude to create for me.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-10221\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/interp_sketch.png\" alt=\"\" width=\"307\" height=\"251\" \/><\/p>\n<p>The idea is that there are four possible candidates that I'm sampling from. How many samples do I need to guess which of the four candidates is being sampled?<\/p>\n<p>Writing an app can be a complicated exercise. But it doesn't have to be when AI is helping you. I'm going to use <a href=\"https:\/\/github.com\/matlab\/prompts\/blob\/main\/prompts\/app-building\/create-programmatic-app.md\">one of our new prompts that is especially designed to make app creation a breeze<\/a>. I'll\u00a0modify the prompt with these directions.<\/p>\n<pre>## Prompt for Interpolant Guessing Game\r\nCreate a MATLAB programmatic app for demonstrating \r\nscattered interpolants.\r\n\r\nWe will demonstrate interpolants with a guessing game: \r\nhow many points do you need to guess the correct shape?\r\n\r\nWe are using a small number of points to interpolate \r\nacross and unknown shape. We have four candidate surfaces \r\nto guess from. These will be four randomly chosen modes \r\nfrom among the first 8 modes of the L-shaped membrane \r\n(where mode n is returned by membrane(n)).\r\n\r\n### The Layout\r\nSee the diagram in the file @sketch.png. On the left is a \r\nplot that shows the current interpolant. On the right are \r\nthe four candidate shapes in a 2-by-2 grid.\r\n\r\nThe interpolant on the left will start out with 10 sample points. \r\nUnderneath the interpolant plot are two buttons: \"+1 sample\" and \r\n\"+10 samples\". \r\n\r\nIn the bottom right is a \"Guess\" editable text field where the \r\nuser is invited to make a guess about which candidate shape is \r\nbeing interpolated. If they enter a value and press return, they\r\nwill be told if they are correct or incorrect.\r\n<\/pre>\n<p>Starting with the prompt from GitHub, I pasted the text shown here into the section called, appropriately, \"The Prompt\" to get a sort of super-prompt. Then I sent Claude on its way. Very quickly it gave me this.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"800\" height=\"475\" class=\"alignnone size-full wp-image-10222\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/game1.png\" alt=\"\" \/><\/p>\n<p>Nice! This is just what I was picturing. Everything worked as expected. I didn't have to worry about UI layout or button logic. It just worked. Here you're seeing an interpolation based on only 10 points. Which of the four potential candidates does this interpolated shape most likely match?<\/p>\n<p>Now I'm going to use the buttons to add a bunch more measurements.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"800\" height=\"475\" class=\"alignnone size-full wp-image-10223\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/game2.png\" alt=\"\" \/><\/p>\n<p>With 215 points, the fog has cleared. Can you see which candidate is being sampled? Why yes, it's Cleve Moler's old friend, the first vibrational mode of a membrane on a square domain with an invariant re-entrant corner, affectionately known around Natick as the <a href=\"https:\/\/blogs.mathworks.com\/cleve\/2014\/10\/13\/mathworks-logo-part-one-why-is-it-l-shaped\/\">L-shaped membrane<\/a>. Looking good, Ellie!<\/p>\n<p>It was fun exercising some basic MATLAB functionality using the latest Copilot. But then, leveraging the MCP Server, it was awesome to quickly create a game that builds on that learning and provides more insight about the nature of interpolation. AI lets you fly around a bigger design space. In the past, I would have had this same idea for a game, but I probably wouldn't have taken the time actually build it. Now it's more like the wave of a magical wand and VOOM! there it is.<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/membrane_samples.png\" onError=\"this.style.display ='none';\" \/><\/div>\n<p>You may have seen the news on the MATLAB Blog that MATLAB Copilot has been updated to the GPT-5 mini model. My experience has shown this to be a huge improvement. So if you haven't tried Copilot yet,... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/community\/2025\/11\/21\/interpolation-games-with-matlab-copilot\/\">read more >><\/a><\/p>\n","protected":false},"author":69,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/10215"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/users\/69"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/comments?post=10215"}],"version-history":[{"count":8,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/10215\/revisions"}],"predecessor-version":[{"id":10230,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/10215\/revisions\/10230"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/media?parent=10215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/categories?post=10215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/tags?post=10215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}