Stuart uses video to share his experiences solving problems with MATLAB day-to-day, interesting new features, plus tips and tricks he has picked up along the way.
My MATLAB based system that detects broken links on mathworks.com pages each night is failing to detect them on a specific page. I need to investigate and understand why, to see if there is a systemic problem.
Features covered in this code-along style video include:
Play the video in full screen mode for a better viewing experience.
I often use sendmail to notify me of the progress of long running scripts, or when they have finished or errored. I have had some trouble recently with our internal mail server, so I wanted to try an alternative method of getting notifications. nfty is an HTTP-based service that allows you to send notifications to your phone or desktop using a REST API. I will try using it from MATLAB.
Features covered in this code-along style video include:
Play the video in full screen mode for a better viewing experience.
My script that looks for translation errors on our website is generating too many false positives. I need to ignore an area at the bottom of all pages, called the country selector which is a list of country names that are not translated. I first try to remove the country name strings after I have extracted the text from the web page, then I realize it would be better to find and remove specific HTML elements before extracting the text.
Features covered in this code-along style video include:
Play the video in full screen mode for a better viewing experience.
When I read data from the web, using webread or websave, usually all records returned have the same information and, as a result, appear in MATLAB as a struct array. But sometimes they do not have the same information and appear as a cell array containing structures with different fields. This has recently happened in one of my scripts, so I need to address this but I think it would be useful for me to come up with a utility to handle this scenario in general, as it often happens.
Features covered in this code-along style video include:
Play the video in full screen mode for a better viewing experience.
My colleague found a bug in my MATLAB Web app. She could see a string concatenation error message in the app logs. I will go through the normal steps I would take to debug and fix such an issue in my apps.
Features covered in this code-along style video include:
Play the video in full screen mode for a better viewing experience.
I have many MATLAB scripts and systems that are scheduled by Windows Task Scheduler or they run continuously in loops. For some of them I need to ensure that they’re always running because they carry out tasks that others rely on. If they fail or the machine they are running on reboots, its a problem.
To handle this, I use a simple method where the script periodically writes to a file, then I have a Power Automate flow check to ensure the file has been updated recently.
Your organization needs to utilize OneDrive or SharePoint and Power Automate for this to work.
Features covered in this code-along style video include:
Play the video in full screen mode for a better viewing experience.
As Cody is having a contest at the moment, I thought I would try and solve a few problems. Here, I take a look at the first few problems in the MATLAB Fundamentals – Matrices and Arrays group.
Features covered in this code-along style video include:
Play the video in full screen mode for a better viewing experience.
I need to add some new controls to my web app that searches the HTML of our website. The web app communicates with another MATLAB via tcp/ip, so I will need to make UI and code changes in the app and also make changes in the script it talks to. I will need to switch back and forth between two machines for this.
Features covered in this code-along style video include:
Play the video in full screen mode for a better viewing experience.
I want to be able to create a string array that is a list of MATLAB releases for the last 10 years. e.g. [“R2014a”, “R2014b”, “R2015a”, “R2015b … “R2025a”].
I could use a for loop, or perhaps a nested for loop, but I suspect I can use the concept of implicit expansion with strings to do this in a simpler way.
Features covered in this code-along style video include:
Play the video in full screen mode for a better viewing experience.
When I make a request to a web service I often use, I normally get back a struct array. Now, however, I have received a cell array of structs and I suspect that the structs have different fields.
I need to figure out how to convert this cell array into a homogenous struct array.
Features covered in this code-along style video include:
Play the video in full screen mode for a better viewing experience.
In a previous blog video, I manually paused my code and changed the value of a variable, in order to change the behavior of my code. This time, my code has stopped at a keyboard command and I want to change the value of a variable, in multiple workspaces, to change the behavior of my code.
Features covered in this code-along style video include:
Play the video in full screen mode for a better viewing experience.
I’ve created quite a few unit tests for one of my MATLAB apps, but I’m not sure if I’m testing all it’s functionality. That is where the Coverage Report comes in. I’m going to use it to see which functions have not been called, to guide me in deciding which tests to add.
Features covered in this code-along style video include:
Play the video in full screen mode for a better viewing experience.
My colleague told me that one of the web apps that I maintain for internal use has stopped working. So I want to investigate the issue and try and fix it. I thought I would show you my typical process for troubleshooting and debugging issues with a web app.
Features covered in this code-along style video include:
Play the video in full screen mode for a better viewing experience.
My app takes a while to start because it has to load a good amount of data from a database, then analyze it before its ready to be used. I have an idea of how to speed this up, so I’m going to use the Profiler, as always, as a first step to understand the execution time.
Features covered in this code-along style video include:
Play the video in full screen mode for a better viewing experience.
I often use tokens and other types of authentication to access web resources. There is one I use where the authentication expires after 1 year, and I’m often taken by surprise by this. So I want to add a check to some existing code that will notify me in advance when the token is about to expire.
Features covered in this code-along style video include:
Play the video in full screen mode for a better viewing experience.
I need to create a simple function to do some string processing in one of my web apps. I thought I would try and show you a typical process of developing the algorithm, creating the function, adding an arguments block and then creating a test script.
Features covered in this code-along style video include:
Play the video in full screen mode for a better viewing experience.
I have a function which analyzes the contents of a few hundred folders. Its taking several minutes to run and I use it a lot, so I want to try and make it execute faster.
I propose using the profiler to try and understand where the time is spent and explore some code changes.
I often find with my performance improvement work, that the first changes I make are to my algorithm, or code architecture. For example, by ensuring that I only execute the computations that I need to. Later, I might then look at speeding up those computations.
Features covered in this code-along style video include:
Play the video in full screen mode for a better viewing experience.
I use parfor a lot when processing large amounts of data. It could be on my local machine, or it could be on a remote cluster. It is very simple to convert a for loop to a parfor loop and often you do not need to change the code in your loop.
A parfor is efficient when the work required for each iteration is similar, but if it’s not, then, near the end of your loop, some workers can become idle. This is where parfevalcan be helpful. It’s a little more complicated to use, but it will keep all workers busy until the work is finished. As a result, you should get your calculation finished sooner.
Here I take a parfor loop in one of my existing scripts, and attempt to convert it to use parfeval instead.
Features covered in this code-along style video include:
Play the video in full screen mode for a better viewing experience.
Here, I make one or two more changes to my class that creates a non-expiring SharePoint token that I made in part 1. Then I go about updating my other functions to make use of the new class.
Features covered in this code-along style video include:
Play the video in full screen mode for a better viewing experience.
I create a lot of code that reads and writes to our internal SharePoint file storage. To do that, it needs to use an authorization token. This token is time limited to an hour and sometimes that causes my code to fail when it expires. I want to create a more robust method of generating a token and my first idea is to create a class that will regenerate the token if it has or is about to expire.
Features covered in this code-along style video include:
Play the video in full screen mode for a better viewing experience.
I have a function that returns the duration of a video file. It only supports standard video files like MP4 or MKV and uses videoReader. I want to add support for animated GIF files which are not supported by videoReader.
Features covered in this code-along style video include:
Play the video in full screen mode for a better viewing experience.
In my last post, I prototyped some code that plots the progress of my data download job. I noticed that the axes were not correct, so I need to fix that and some other issues.
Features covered in this code-along style video include:
Play the video in full screen mode for a better viewing experience.
I have a script that runs for many hours and downloads a large amount of data from a web service. It sometimes slows down or even stops, so I want to be able to understand its progress better by visualizing it. I plan to try adding a plot in the main loop and update it each time.
Features covered in this code-along style video include:
Play the video in full screen mode for a better viewing experience.
Here I finish developing a local file cache for my video analysis function. In this phase, I incorporate the changes I made to my function into a web app that uses it. I hope it will greatly reduce the start time of the app.
Features covered in this code-along style video include:
Play the video in full screen mode for a better viewing experience.
Here I continue developing a local file cache for my recurring data analysis job. Next, I want to add support for new videos being added to the SharePoint folder.
Features covered in this code-along style video include:
Play the video in full screen mode for a better viewing experience.
I have a recurring MATLAB processing job that analyzes the metadata of the files in a large SharePoint folder. It can take several minutes to get all the metadata. However, the metadata in older files rarely changes. So I thought I would try and implement a local file cache that stores the meta data of all the files, and only goes to SharePoint for new or updated files.
Features covered in this code-along style video include:
Play the video in full screen mode for a better viewing experience.
48:02
I need to be able to download the audio transcript of an existing Microsoft SharePoint video, modify it and re-upload it. I already have a few functions and components that will help me do this. I... read more >>
4:03
I have a bug in my script which removes an element of a string array unexpectedly. So I plan to watch the contents in the variable editor as I step through my code each line at a time, to help me... read more >>
30:45
Here I want to upload a time-stamped caption file to a SharePoint video using their REST API. This will let me navigate and browse interesting events in the video. I’m going to use the same... read more >>
15:51
In my last post, I developed a script to delete the past versions of a SharePoint file using the REST API. Now, I want to delete past versions of all the files in a folder. I think I’ll start... read more >>
I need to delete all the past versions of a set of files on SharePoint because they are taking up too much space. I’m going to try and use the SharePoint RESTful API to do this, which I have used for other applications.
Features covered in this code-along style video include:
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);}})();
Play the video in full screen mode for a better viewing experience.
This video uses a different recording style from my others. Rather than recording continuously while I work, I pause recording when my code changes are taking a long time to execute or I have some repetitive editing tasks. The pausing of the recording effectively edits my video down to a shorter duration.
This lets me show you real projects and problems that typically take many hours to solve, ones that involve lots of troubleshooting, investigating, debugging, trial and error, and thinking.
I was working on this particular example for most of a day but the resulting video is just 90 min which, yes, is still too long. Feel free to play at a higher speed and skip around. Next time I will try and be more aggressive in my pausing.
So, getting to the problem itself, I have some code that processes hundreds of large CSV files, which describe a graph of the connections between our website pages each day. It takes several minutes to load and analyze each file, and the total running time is several hours. So I want to look at trying to speed it up.
I plan to work on these aspects:
Features covered in this code-along style video include:
Play the video in full screen mode for a better viewing experience.
You many not be aware that you can debug the code contained inside a section (marked by %%) without needing to run your entire file. This can be useful when you are working on a small area of code, using the data calculated from previous sections, that has not changed and may take a while to recalculated. Here I show an example.
Features covered in this code-along style video include:
Play the video in full screen mode for a better viewing experience.
Here I want to modularize and re-use part of my code by converting it to a function, but in this case the automatic conversion in the editor is not supported, so I need to do it manually.
Features covered in this code-along style video include:
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);}})();
Play the video in full screen mode for a better viewing experience.
I often need to call external command line tools from MATLAB to carry out various specialized tasks. Here I plan to make a utility that calls the FFmpeg tool to concatenate video files.
Features covered in this code-along style video include:
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);}})();
Play the video in full screen mode for a better viewing experience.
I’m trying to parallelize a script that takes a few hours to run. I normally use parfor, the simplest parallel construct, but to do that, I need to modify how I index through my dataset.
Features covered in this code-along style video include:
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);}})();
Play the video in full screen mode for a better viewing experience.
I was told by a colleague that one of by MATLAB string searching web apps did not work for Chinese strings. After investigating, I realized the way I implemented it limited support to ACSII characters. So I need to update my code in a couple of places to get it to work.
Features covered in this code-along style video include:
Play the video in full screen mode for a better viewing experience.
Here, my code has errored-out and paused in a function. I want to recover the data because the code had been function for a few hours. I’ve done this before by saving the data temporarily to a MAT-file but here I use assignin instead.
Features covered in this code-along style video include:
Play the video in full screen mode for a better viewing experience.
I want to update a static method in a class to return the latest file in a folder rather than a fixed filename.
Features covered in this code-along style video include:
Follow me (@stuartmcgarrity) if you want to be notified via Twitter when I post.
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);}})();
Play the video in full screen mode for a better viewing experience.
32:31
Here I want to add a “Row Totals” column to a pivot table in the web app that I’m working on. I need to add my UI control and update my code to calculate the totals column and add... read more >>
3:36
Here is an typical example of converting a script to a function. In this case, as well using the code analyzer to specify the function name, I need to define input arguments and manage a sub... read more >>
33:20
A few years time ago I developed a mechanism and MATLAB function to track values over time I was interested in monitoring. However, I found that storing the data in MAT files made it inconvenient to... read more >>
8:09
Here is a video I recorded not long after 22a was released, but I haven’t posted it yet. It shows an example of using “Pause on Error” with MATLAB App Designer, which is a very... read more >>
28:17
Previously, I used a parfor loop to make a bunch of web requests. Here I want to use a parfor loop to download the HTML for a large number of pages on our website, then store the content in a string... read more >>
12:20
I need to update a drop-down UI control in my app so that the items in the list are no longer truncated. I will need to edit my code that populates it, run my tests and re-commit. Features covered in... read more >>
8:18
After I added a new UI control to my web app, in a live stream recently, I ran my full set of unit tests and one failed. So I need to investigate why and address. Features covered in this code-along... read more >>
7:30
Here I want to change the behavior of a long running script, by pausing it and manually changing the value of one of the variables. This lets the program continue to run, but in a different way, and... read more >>
22:39
Some data in my MATLAB function is not being filtered out as it should be. I will need to determine why, by doing some investigating, stepping through my code and analyzing the variable values at... read more >>
20:17
Here, I add a cell selection callback to a table in one of my MATLAB apps by copying this functionality from another app. Features covered in this code-along style video include:
App... read more >>
10:52
While trying to troubleshoot another bug, which I couldn’t reproduce, I found something else I want to fix. I have a number of data files in my MATLAB project subfolders that the code in each... read more >>
3:23
The “Run/Continue to Here” button in the MATLAB Editor, lets you jump to a future spot in your code in one click and without setting a breakpoint. This replaced the “Run to... read more >>
I’ll be doing my Blog live today on YouTube at 11am EDT. It will be a code-along as I normally do, mostly working with App Designer, but I’ll try and answer the occasional question from... read more >>
14:49
The unit tests for my web app have failed because I added a new variable to my data set. Rather than re-design my tests I’ve decided to take the lazy way out for now and update my app to ignore... read more >>