Accelerating prototyping with AI: From MATLAB Code to a Shiny App in less than 1 hour

Accelerating prototyping with AI: From MATLAB Code to a Shiny App in less than 1 hour

I had to recently transform a MATLAB codebase into an interactive R Shiny application, so I wanted to test how combining expert knowledge with AI-assisted coding can significantly accelerate software prototyping. I wrote the original MATLAB code few days ago starting from some old code I had from my PhD, in which I had to plot an interpolated surface representing the output of a stochastic parameter optimization for a ML model.

The Process

The code was obviously rich with functions for surface interpolation, Gaussian smoothing, and 2D peak detection, so I gave o3 a great head start. 😜

Replicating MATLAB’s scattered data interpolation and 2D peak detection was easy, o3 also suggested a way to improve my peak detection (I already knew my scientific coding during PhD was not that great, thank you, o3).A Gaussian smoothing filter was implemented in R to mimic MATLAB’s conv2 functionality. Since R doesn’t include conv2 out-of-the-box (or at least, I didn't know libraries to do that immediately), I experimented with few solutions. o3 suggested initially a spatial-based implementation of the 2D convolution, which was (obviously) laggy and computationally expensive. I asked o3 to implement an FFT‐based convolution, which is known to improve speed for large kernel size (i.e., when kernel range is large and kernel step is small, like in my case). During this phase, I encountered issues like NaNs appearing in the results and unexpected data type problems, but with clear, circumstantiated feedback I guided o3 through debugging: ensuring proper numeric coercion, avoiding NaNs values in the interpolation, and refining the FFT‐based convolution function to return correctly shaped numeric matrices, we reached a very satisfying result (see images below).

With a reliable interpolation, smoothing, and peak detection backend, I integrated everything into a Shiny app. Shiny app components were finalized in no time, like slider controls for grid resolution, kernel parameters, smoothing scale, and peak threshold. Interactive visualizations (a 3D surface plot and a contour plot) provide immediate feedback on parameter adjustments.

Total Interaction Time: Less than 1 hour.

The Outcome

Final result is probably not that visually appealing, but hey, I am an engineer!

This is a great example of how technical know‐how combined with the powerful reasoning and coding assistance of LLMs, can dramatically speed up software prototyping and problem solving.

The possibilities offered by LLMs to transform workflows and accelerate innovation are countless!


Article content
Shiny App for surface interpolation, smoothing and peak detection - View of example data with smoothed surface and peaks on local maxima location


Article content
Shiny App for surface interpolation, smoothing and peak detection - View of example data with contour plot and peaks on local maxima location


To view or add a comment, sign in

Insights from the community

Others also viewed

Explore topics