File Exchange Pick of the Week https://blogs.mathworks.com/pick Jiro and Sean share favorite user-contributed submissions from the File Exchange. Sat, 16 Mar 2024 03:42:01 +0000 en-US hourly 1 https://wordpress.org/?v=6.2.2 Celebrating Pi Day with cool visualizations https://blogs.mathworks.com/pick/2024/03/15/celebrating-pi-day-with-cool-visualizations/?s_tid=feedtopost https://blogs.mathworks.com/pick/2024/03/15/celebrating-pi-day-with-cool-visualizations/#respond Sat, 16 Mar 2024 03:40:54 +0000 https://blogs.mathworks.com/pick/?p=16672 Jiro's Pick this week is Happy Pi Day by Zhaoxu Liu / slandarer.I'm a couple of days late, but I wanted to highlight this set of cool visualizations by Zhaoxu for Pi Day. It's amazing to see so many... read more >>

]]>
Jiro's Pick this week is Happy Pi Day by Zhaoxu Liu / slandarer.
I'm a couple of days late, but I wanted to highlight this set of cool visualizations by Zhaoxu for Pi Day. It's amazing to see so many different types of visualizations using π. Read through this post by Zhaoxu with explanations for the visualizations.
PiLogoDemo.png
I will let you read his post and play with the code yourself, but I'd like to end with one visualization that is fitting during this cherry blossom season.
PiTreeDemo.png

Comments

Give the Pi Day visualizations a try on MATLAB Online. Let us know what you think.
]]>
https://blogs.mathworks.com/pick/2024/03/15/celebrating-pi-day-with-cool-visualizations/feed/ 0
Statistical visualization functions and “Open in MATLAB Online” https://blogs.mathworks.com/pick/2024/01/27/statistical-visualization-functions-and-open-in-matlab-online/?s_tid=feedtopost https://blogs.mathworks.com/pick/2024/01/27/statistical-visualization-functions-and-open-in-matlab-online/#comments Sat, 27 Jan 2024 16:27:05 +0000 https://blogs.mathworks.com/pick/?p=16625

Jiro's Pick this week is dabarplot, daviolinplot, daboxplot by Povilas Karvelis.Today, I'd like to highlight a couple of things in this post.Statistical visualization functions"Open in MATLAB Online"... read more >>

]]>
Today, I'd like to highlight a couple of things in this post.
  • Statistical visualization functions
  • "Open in MATLAB Online" button

Statistical Visualization

Povilas provides 3 statistical visualization functions, especially for visualizing distributions. They all come with a rich set of parameters for customizations.
dabarplot
dabarplot_examples.png
daviolinplot
daviolinplot_examples.png
daboxplot
daboxplot_examples.png

Open in MATLAB Online

Have you ever wanted to quickly try out the File Exchange entries? Are you on a computer that doesn't have MATLAB installed? You can now open File Exchange entries directly in MATLAB Online! You don't need to download the file to try it out. You can run everything through your browser. Read about it here.
OpenInMATLABOnline.gif
You can also share a URL that would open the File Exchange entry directly in MATLAB Online, by clicking on the "Share" button.

Comments

Give the visualization functions a try on MATLAB Online. Let us know what you think.
]]>
https://blogs.mathworks.com/pick/2024/01/27/statistical-visualization-functions-and-open-in-matlab-online/feed/ 2
Simulate Home Battery Management System https://blogs.mathworks.com/pick/2023/08/15/simulate-home-battery-management-system/?s_tid=feedtopost https://blogs.mathworks.com/pick/2023/08/15/simulate-home-battery-management-system/#comments Tue, 15 Aug 2023 09:15:23 +0000 https://blogs.mathworks.com/pick/?p=16598

Jiro's Pick this week is Home Battery Energy Management System by Rodney Tan.I met Dr. Rodney Tan at a virtual educator workshop we held last year, and there I learned that he is very active in the... read more >>

]]>
I met Dr. Rodney Tan at a virtual educator workshop we held last year, and there I learned that he is very active in the community with over 100 File Exchange entries. His entries are educational in nature, and they help illustrate concepts through simulations and interactivity.
The other day, I was looking through his entries, and this one on Home Battery Management System caught my attention. One of my neighbors just recently installed an array of solar panels on their roof and a home energy management system. Since then, I had been curious about how it all worked. When I read up on it, I saw phrases such as photovoltaic capacity, number of panels, inverter efficiency, and state of charge. This Simulink model by Dr. Tan helped me better understand how it worked by connecting these parameters to the simulation output.
Sample input data sets (solar radiation and home load) are provided with this entry, so you can get a simulation of how the battery state of charge changes over time and how much energy is imported from or exported to the grid.
From the scope, you can see that the state of charge increases with solar radiation and decreases with load. Energy is exported to the grid when the state of charge is above a threshold and is imported from the grid when the state of charge is below a threshold.
Simulation models such as this help deepen the understanding of complex concepts.

Comments

Give this entry a try and leave a comment for Dr. Tan. If you liked this entry, you should also check out the other entries by him. In addition to macro-level models such as this entry, he also has many component-level simulation models.
]]>
https://blogs.mathworks.com/pick/2023/08/15/simulate-home-battery-management-system/feed/ 1
MCmatlab: A Monte Carlo simulation for photon transport in 3D voxel space https://blogs.mathworks.com/pick/2023/06/13/mcmatlab-a-monte-carlo-simulation-for-photon-transport-in-3d-voxel-space/?s_tid=feedtopost Tue, 13 Jun 2023 14:43:09 +0000 https://blogs.mathworks.com/pick/?p=16550

Today, I am inviting Temo, who is from the academic discipline marketing team, and he looks after the physics discipline. He will share his Pick from the field of optics.This week's Pick is MCmatlab... read more >>

]]>
Today, I am inviting Temo, who is from the academic discipline marketing team, and he looks after the physics discipline. He will share his Pick from the field of optics.
This week's Pick is MCmatlab developed by DrDonik from University of Bern and Dr. Anders Kragh Hansen from Technical University of Denmark.
Light and optics’ role in medical diagnostics and treatments cannot be overstated. A broadly applicable equation modeling the propagation of light within biological tissue is called the Radiative Transfer Equation (RTE). The RTE is commonly solved with Monte Carlo techniques, starting from modeling the paths of photons traveling through the tissue as a random walk. Monte Carlo simulations statistically sample the step size of the random walk and angular deflection per scattering event, yielding, after averaging over many photons’ paths, realistic approximations to light’s propagation in tissue. mcxyz.c is a celebrated Monte Carlo program, coded in C, for modeling light propagation in heterogenous tissue written by a pioneer in biomedical optics, Steven L. Jacques. It is usually combined with MATLAB to generate the input optical properties of tissue types for a given illumination, allowing the users to create the three-dimensional (3D) structure of the desired heterogeneous tissue.
MCmatlab converts (wraps) mcxyz.c to a compact tool usable directly through a MATLAB interface, without the need to leave the MATLAB environment. It thus combines the speed of C with the versatility and user-friendliness of MATLAB. In addition to the RTE solver, MCmatlab includes a thermal solver, useful for simulating processes such as photocoagulation. The results of simulation are shown using interactive 3D volumetric slice plotting as shown below.
mcmatlab_animation.gif
MCmatlab provides researchers with easy access points to simulate light–tissue interaction[1] and has also been used to simulate light transport in luminescent materials[2] such as phosphors. It is especially useful for helping students understand the underlying physics in light-tissue interactions without demanding experience in C programming or UNIX systems, making it preferred tool of educators for teaching biophotonics.
The entry comes with detailed documentation and a large collection of examples to get you started. Give this a try and let us know what you think.
  1. Boonya-ananta, T., Rodriguez, A.J., Ajmal, A. et al. Synthetic photoplethysmography (PPG) of the radial artery through parallelized Monte Carlo and its correlation to body mass index (BMI), Sci Rep 11, 2570 (2021). https://doi.org/10.1038/s41598-021-82124-4
  2. Krasnoshchoka, A., Hansen, A. K., Thorset, A. et al. Phosphor material dependent spot size limitations in laser lighting, Optics Express Vol. 28, Issue 4, pp. 5758-5767 (2020), https://doi.org/10.1364/OE.383866
]]>
Bouncing Rod Simulator https://blogs.mathworks.com/pick/2023/02/20/bouncing-rod-simulator/?s_tid=feedtopost https://blogs.mathworks.com/pick/2023/02/20/bouncing-rod-simulator/#comments Mon, 20 Feb 2023 14:00:09 +0000 https://blogs.mathworks.com/pick/?p=16452

Jiro's Pick this week is Bouncing Rod Simulator by Matthew Sheen.As a mechanical engineer, I love simulating physical phenomena. When you have equations of motion, you can easily simulate them in... read more >>

]]>
Jiro's Pick this week is Bouncing Rod Simulator by Matthew Sheen.
As a mechanical engineer, I love simulating physical phenomena. When you have equations of motion, you can easily simulate them in MATLAB using ODE solvers. Of course, you can also simulate dynamic systems with Simulink or with our physical modeling tools. With ODE solvers, you can detect events to simulate things like a bouncing ball. (By the way, here's an example of a bouncing ball simulated using Simulink).
When I saw this simulation of a bouncing rod by Matthew, it brought me a smile. This is a nice extension to the bouncing ball simulator:
  • The rod moves in 2 dimensions. Positional states include $ \left[x, y, \dot{x}, \dot{y}\right] $
  • The rod can also rotate. Rotational states include $ \left[\theta, \dot{\theta}\right] $
  • Collision (contact) with the ground can happen in multiple cases: top tip of the rod hitting the ground, bottom tip of the rod hitting the ground, or the rod hitting the ground (mostly) parallel to the ground. Based on the situation, the new states for the rod are calculated.
  • There are two different modes of operation: flight and sliding. Typically the rod is in flight mode. When the rod reaches a certain state, it eventually switches to sliding mode.
Once the simulation finishes, it shows the animation of the dynamics.
bouncing_rod_animation.gif
This is a great example to understand the concept of ODE solvers and the event-handling capability of the solvers. This serves the purpose of teaching those concepts. There are, however, a couple of additional effects that could be added to this simulation to make it even more true to the physics.
  • Add friction - you can see this especially once the rod goes into sliding mode. The rod keeps sliding forever. Adding frictional forces to slidingPhase.m can accomplish this.
  • Improve the switching logic for sliding - currently, the rod switches to sliding mode when it detects that the center of mass (COM) is close to the ground. This logic indicates that when the COM is close to zero, the rod is nearly parallel to the ground. This may be a reasonable logic for most cases. However, it doesn't accurately represent a case where the rod falls down flat on the ground with vertical speed. In reality, the rod will bounce up due to impact, but the simulation switches to sliding in this case. Here's an example of a case where the rod falls parallel to the ground. One approach would be to look at not just the COM but also the vertical speed of the rod. Another approach is to calculate the states after collision, and switch to sliding mode only if the vertical speed is below a threshold.
flat_fall.gif
These are improvement ideas, but they don't take away any of the value this entry provides to people wanting to simulate dynamic systems with event handling.

Comments

Very well done, Matthew! Give this a try and let us know what you think here or leave a comment for Matthew.
]]>
https://blogs.mathworks.com/pick/2023/02/20/bouncing-rod-simulator/feed/ 3
MatCal https://blogs.mathworks.com/pick/2023/01/20/matcal/?s_tid=feedtopost Fri, 20 Jan 2023 14:42:13 +0000 https://blogs.mathworks.com/pick/?p=16422

Will's pick this week is MatCal by Bryan. I'm no archaeologist, but I read a fair number of books that cover the topic. A common point of discussion is the wonder and challenges of radiocarbon... read more >>

]]>
Will's pick this week is MatCal by Bryan.

I'm no archaeologist, but I read a fair number of books that cover the topic. A common point of discussion is the wonder and challenges of radiocarbon dating. You find yourself organic remains from an ancient site. Take it to the lab and calculate the ratio of carbon 14 to carbon 12 in the sample. Compare that ratio to present organic material. Since carbon 14 decays over time and the remains aren't absorbing fresh carbon 14 from the atmosphere, you can estimate how old it is.

This line of reasoning works well enough if you assume that the ratio of carbon 14 in the atmosphere is constant. But while cosmic rays are regularly creating new carbon 14 isotopes in the air, the ratio does fluctuate over time. There are other factors to consider with the net effect being that you need to adjust dating estimates to improve its accuracy.

Bryan's submission provides a simple function to calibrate carbon 14 dating. You provide the uncalibrated dating estimate and range of uncertainty. You tell it which of thirteen calibration models you'd like to use, and it will adjust your findings. Here's a plot produced for a 4,000 year old sample with a 1 sigma uncertainty of 100 years. I used the IntCal20 model, which was developed in 2020 based on tree rings. The old probability distribution (y axis) is compared against the new probability distribution (x axis) with the calibration curve shown on the main figure. The revised estimate of the specimen's age is more likely to be 4,500 years old.

I had read that calibration of marine samples required different considerations. Carbon 14 amounts in the oceans is different than the atmosphere. Nevertheless, I was surprised by how different the results were when I used the Marine20 model. The same input parameters yielded an estimate around 3,800 years, quite a bit younger than with the IntCal20 model.



Bryan's contribution remains popular more than a decade after he initially posted it. I applaud him for continuing to maintain things. His most recent update was made in 2021. For the next iteration, I suggest taking a look at function argument validation. I see your comment on line 126, and I think this might help you out!

Let us know what you think here or leave a comment for Bryan.]]>
Figures for Dark Mode https://blogs.mathworks.com/pick/2022/10/19/figures-for-dark-mode/?s_tid=feedtopost https://blogs.mathworks.com/pick/2022/10/19/figures-for-dark-mode/#comments Wed, 19 Oct 2022 13:00:30 +0000 https://blogs.mathworks.com/pick/?p=16212

Jiro's Pick this week is dark mode plot by Natan.Do you work in dark mode? If you do, you need to take a look at this entry by Natan, especially if you make presentations using the dark theme. As you... read more >>

]]>
Jiro's Pick this week is dark mode plot by Natan.
Do you work in dark mode? If you do, you need to take a look at this entry by Natan, especially if you make presentations using the dark theme. As you know, standard plots in MATLAB are created with white background.
figure
plot((1:2:9).*sin((1:10)'))
If we copy and paste this into a dark theme presentation, it's probably not what you want.
normal_plot.png
Just run plot_darkmode and it does the appropriate color conversions. The background is set to a dark theme, the text and axes colors are set to white, and the line colors are adjusted accordingly.
plot_darkmode
Copy and paste into a slide, and voila!
darkmode_plot.png
It's also worth noting that the line colors are adjusted so that they are appropriately visible in dark mode. For instance, let's create a plot with two lines, a black line and a dark red line.
plot(rand(5,1),"k","LineWidth",2) % black line
hold on
plot(rand(5,1),"Color",[.5 0 0],"LineWidth",2) % dark red line
hold off
legend("Data 1", "Data 2")
You can imagine that simply setting the background to a dark theme will not work. Both lines will be hardly visible. When we run plot_darkmode, you can see that the line colors are adjusted appropriately.
plot_darkmode

Comments

Very nice entry, Natan!
Give this a try and let us know what you think here.
]]>
https://blogs.mathworks.com/pick/2022/10/19/figures-for-dark-mode/feed/ 2
Random String Utility https://blogs.mathworks.com/pick/2022/10/07/random-string-utility/?s_tid=feedtopost Fri, 07 Oct 2022 13:01:26 +0000 https://blogs.mathworks.com/pick/?p=16178

Will's pick this week is Random String Utility by Dan Couture. This is an oldie but a goodie. This submission is from 2012 but still works just fine in R2022b (another testament to the... read more >>

]]>
Will's pick this week is Random String Utility by Dan Couture.

This is an oldie but a goodie. This submission is from 2012 but still works just fine in R2022b (another testament to the compatibility of MATLAB over time). It's a simple enough utility that returns a array of random text characters. The user can specify the length of the number of characters and the pool of characters to draw from: upper case letters, lower case letters, or all alphanumeric and special characters. Some example output:



What would you use this for? Well, it could be handy for generating test input data to functions that work with char or string data. It would also be helpful for name mangling. Can you think of any other use cases?

Note that the submission says it generates a random string when it's actually producing a character array. The file precedes the release of the string data type in 2016. In the screenshot above, I show how to quickly convert to a string variable.

Let us know what you think here or leave a comment for Dan.]]>
Learning programming through game building https://blogs.mathworks.com/pick/2022/08/12/learning-programming-through-game-building/?s_tid=feedtopost Fri, 12 Aug 2022 19:00:15 +0000 https://blogs.mathworks.com/pick/?p=16148

Jiro's Pick this week is AstroVolley Courseware by Paul Huxel.Back in my undergraduate studies (many, many years ago), I took a Pascal programming course, and it was the first official programming... read more >>

]]>
Jiro's Pick this week is AstroVolley Courseware by Paul Huxel.
Back in my undergraduate studies (many, many years ago), I took a Pascal programming course, and it was the first official programming language I learned. I still claim MATLAB as my first programming language I learned, since I have never used Pascal beyond that one course. What I really enjoyed about the Pascal course was that we learned the language as we built an artillery game. We learned about graphics, animation, loops, and other standard programming constructs.
When I saw AstroVolley, it brought back good memories from my programming course. This courseware is perfect for teaching basic programming, plotting, and app building in MATLAB. It teaches the concepts necessary to build the game step by step.
astrovolley_anim.gif
Paul includes an instructor guide, which can be used as lecture notes. Here is the complete lesson plan.
It starts from simple plotting for drawing the ships (triangles) and then celestial bodies (circles). Loops are introduced to plot multiple bodies in a more efficient way. Trajectories are visualized through animations. Finally, all of this is put together into an app with the App Designer. Paul also adds a nice touch by explaining the physics behind gravity and orbits.
What I really like is that he includes live scripts and apps for each concept, with fill-in-the-blank tasks for students to work on.
plotting_task.gif

Comments

Very well done, Paul! Give this a try and let us know what you think here.
]]>
Get your subplots the way you want it with subplotHelper https://blogs.mathworks.com/pick/2022/07/01/get-your-subplots-the-way-you-want-it-with-subplothelper/?s_tid=feedtopost Fri, 01 Jul 2022 13:00:56 +0000 https://blogs.mathworks.com/pick/?p=16037

Jiro's Pick this week is subplotHelper by my Frederick Zittrell.Did you know that subplot can be used to create non-uniformly distributed axes? For example,figuresubplot(3,3,1),... read more >>

]]>
Jiro's Pick this week is subplotHelper by my Frederick Zittrell.
Did you know that subplot can be used to create non-uniformly distributed axes? For example,
figure
subplot(3,3,1), text(0.5,0.5,"1","FontSize",24,"Color","red")
subplot(3,3,2), text(0.5,0.5,"2","FontSize",24,"Color","red")
subplot(3,3,3), text(0.5,0.5,"3","FontSize",24,"Color","red")
subplot(3,3,[4 7]), text([.5 .5],[.25 .75],["7" "4"],"FontSize",24,"Color","red")
subplot(3,3,[5 9]), text([.25 .25 .75 .75],[.25 .75 .25 .75],["8" "5" "9" "6"],"FontSize",24,"Color","red")
As you can see, the third input argument to subplot can be a vector that specifies the corners of the rectangular region. It's not too complicated, but it does require some thought to figure out the appropriate parameters.
subplotHelper helps you get these parameters by allowing you to interactively select the layout. Here's the tool in action.
Very nice!

Check out tiledlayout (introduced in R2019b)

On a related note, if you're using R2019b or later, check out the new function tiledlayout and nexttile. These give you a bit more control and additional capabilities for axes layout over subplot. One of my favorite features of tiledlayout is the "flow" option that automatically adjusts the layout based on the figure size and shape.
Of course, tiledlayout can have non-uniform distribution, just like with subplot.

Comments

Give subplotHelper a try, and let us know what you think here.
]]>