主要内容

搜索

The Cody Contest 2025 is underway, and it includes a super creative problem group which many of us have found fascinating. The theme, expertly curated by @Matt Tearle, is humorously centered around the whims of the capricious dictator Lord Ned, as he goes out of his way to complicate the lives of his subjects and visitors alike. We cannot judge whether there's any truth or not to the rumors behind all the inside jokes, but it's obvious the team had a lot of fun curating these; and we had even more fun solving them.
Today I want to showcase a way to graphically solve and visualize one of those problems which I found very elegant, The Bridges of Nedsburg.
To briefly reiterate the problem, the number of islands and the arrangement of bridges of the city of Nedsburg are constantly changing. Lord Ned has decided to take advantage of this fact by charging visitors with an increasingly expensive n-bridge pass which allows them to cross up to n bridges in one journey. Provided the Connectivity Matrix C, we are tasked to calculate the minimum n needed so that there is a path from every island to every other island in n steps or fewer.
Matt kindly provided us with some useleful bit of math in the description detailing how to calculate the way to get from one island to another in an number of m steps. However, he has also hidden an alternative path to the solution in plain sight, in one of the graphs he provided. This involves the extremely useful and versatile object digraph, representing directed graphs, which have directional edges connecting the nodes. Some further useful documentation on the topic for those who are interested in learning more about it:
Let's start using this object to explore a graphical solution to Lord Ned's conundrum. We will use the unit tests included in the problem to visualize the solution. We can retrieve the connectivity matrix for each case using the following function:
function C = getConnectivityMatrix(unit_test)
% Number or islands and arrangement
switch unit_test
case 1
m = 3; idx = [3;4;8];
case 2
m = 3; idx = [3;4;7;8];
case 3
m = 4; idx = [2;7;8;10;13];
case 4
m = 4; idx = [4;5;7;8;9;14];
case 5
m = 5; idx = [5;8;11;12;14;18;22;23];
case 6
m = 5; idx = [2;5;8;14;20;21;24];
case 7
m = 6; idx = [3;4;7;11;18;23;24;26;30;32];
case 8
m = 6; idx = [3;11;12;13;18;19;28;32];
case 9
m = 7; idx = [3;4;6;8;13;14;20;21;23;31;36;47];
case 10
m = 7; idx = [4;11;13;14;19;22;23;26;28;30;34;35;37;38;45];
case 11
m = 8; idx = [2;4;5;6;8;12;13;17;27;39;44;48;54;58;60;62];
case 12
m = 8; idx = [3;9;12;20;24;29;30;31;33;44;48;50;53;54;58];
case 13
m = 9; idx = [8;9;10;14;15;22;25;26;29;33;36;42;44;47;48;50;53;54;55;67;80];
case 14
m = 9; idx = [8;10;22;32;37;40;43;45;47;53;56;57;62;64;69;70;73;77;79];
case 15
m = 10; idx = [2;5;8;13;16;20;24;27;28;36;43;49;53;62;71;75;77;83;86;87;95];
case 16
m = 10; idx = [4;9;14;21;22;35;37;38;44;47;50;51;53;55;59;61;63;66;69;76;77;84;85;86;90;97];
end
C = zeros(m);
C(idx) = 1;
end
The case in the example refets to unit test case 2.
unit_test = 2;
C = getConnectivityMatrix(unit_test);
disp(C)
0 1 1 0 0 1 1 0 0
We now calculate the digraph object D, and visualize it using its corresponding plot method:
D = digraph(C);
figure
p = plot(D,'LineWidth',1.5,'ArrowSize',10);
This is the same as the graph provided in the example. Another very useful method of digraph is shortestpath. This allows you to calculate the path and distance from one single node to another. For example:
% Path and distance from node 1 to node 2
[path12,dist12] = shortestpath(D,1,2);
fprintf('The shortest path from island %d to island %d is: %s. The minimum number of steps is: n = %d\n', 1, 2, join(string(path12), ' -> '),dist12)
The shortest path from island 1 to island 2 is: 1 -> 2. The minimum number of steps is: n = 1
% Path and distance from node 2 to node 1
[path21,dist21] = shortestpath(D,2,1);
fprintf('The shortest path from island %d to island %d is: %s. The minimum number of steps is: n = %d\n', 2, 1, join(string(path21), ' -> '),dist21)
The shortest path from island 2 to island 1 is: 2 -> 3 -> 1. The minimum number of steps is: n = 2
We can visualize these using the highlight method of the graph plot:
figure
p = plot(D,'LineWidth',1.5,'ArrowSize',10);
highlight(p,path12,'EdgeColor','r','NodeColor','r','LineWidth',2)
highlight(p,path21,'EdgeColor',[0 0.8 0],'LineWidth',2)
But that's not all! digraph can also provide us with a matrix of the distances D, i.e. the steps needed to travel from island i to island j, where i and j are the rows and columns of D respectively. This is accomplished by using its method distances. The distance matrix can be vizualized as:
d = distances(D);
figure
% Using pcolor w/ appending matrix workaround for convenience
pcolor([d,d(:,end);d(end,:),d(end,end)]);
% Alternatively you can use imagesc(d), but you'll have to recreate the grid manually
axis square
set(gca,'YDir','reverse');
set(gca,{'XTick','YTick'},{[],[]});
[X,Y] = meshgrid(1:height(d));
text(X(:)+0.5,Y(:)+0.5,string(d(:)),'FontSize',11)
colormap(interp1(linspace(0,1,4), [1 1 1; 0.7 0.9 1; 0.6 0.7 1; 1 0.3 0.3], linspace(0,1,8)))
clim([-0.5 7+0.5])
This confirms what we saw before, i.e. you need 1 step to go from island 1 to island 2, but 2 steps for vice versa. It also confirms that the minimum number of steps n that you need to buy the pass for is 2 (which also occurs for traveling from island 3 to island 2). As it's not the point of the post to give the full solution to the problem but rather present the graphical way of visualizing it I will not include the code of how to calculate this, but I'm sure that by now it's reduced to a trivial problem which you have already figured out how to solve.
That being said, now that we have the distance matrix, let's continue with the visualizations. First, let's plot the corresponding routes that each of these combinations:
figure
tiledlayout(size(C,1),size(C,2),'TileSpacing','tight','Padding','tight');
for i = 1:size(C,1)
for j = 1:size(C,2)
nexttile
hold on
box on
set(gca,{'XTick','YTick'},{[],[]});
p = plot(D,'ArrowSize',10);
highlight(p,shortestpath(D,i,j),'EdgeColor','r','NodeColor','r','LineWidth',2);
lims = axis;
text(lims(1)+diff(lims(1:2))*0.05,lims(3)+diff(lims(3:4))*0.9,sprintf('n = %d',d(i,j))) % Or use from shortest path
end
end
This allows us to go from the distance matrix to vizualizing the routes and numbers of test for each corresponding case. Things are rather simple for the this 3-island example case, but evil Lord Ned is just getting started. Let's now try to solve to problem for all provided unit test cases:
% Cell array of connectivity matrices
C = arrayfun(@getConnectivityMatrix,1:16,'UniformOutput',false);
% Cell array of corresponding digraph objects
D = cellfun(@digraph,C,'UniformOutput',false);
% Cell array of corresponding distance matrices
d = cellfun(@distances,D,'UniformOutput',false);
% id of solutions: Provided as is to avoid handing out the code to the full solution
id = [2, 2, 9, 3, 4, 6, 16, 4, 44, 43, 33, 34, 7, 18, 39, 2];
First, let's plot the distance matrix for each case:
figure
tiledlayout('flow','TileSpacing','compact','Padding','compact');
% Vary this to plot different combinations of cases
plot_cases = 1:numel(C);
for i = plot_cases
nexttile
hold on
box on
axis tight square
pcolor([d{i},d{i}(:,end);d{i}(end,:),d{i}(end,end)]);
set(gca,'YDir','reverse');
set(gca,{'XTick','YTick'},{[],[]});
title(sprintf('Case %d',i),'FontWeight','normal','FontSize',8)
end
c = colorbar('Ticks',0:7,'TickLength',0,'Limits',[-0.5 7+0.5],'FontSize',8);
c.Layout.Tile = 'East';
c.Label.String = 'Number of Steps';
c.Label.FontSize = 8;
colormap(interp1(linspace(0,1,4), [1 1 1; 0.7 0.9 1; 0.6 0.7 1; 1 0.3 0.3], linspace(0,1,8)))
clim(findobj(gcf,'type','axes'),[-0.5 7+0.5])
We immediately notice some inconsistencies, perhaps to be expected of the eccentric and cunning dictator. Things are pretty simple for the configurations with a small number of islands, but the minimum number of steps n can increase sharply and disproportionally to the additional number of islands. Cases 8 and 9 in particular have a relatively large n (proportional to their grid dimensions), and case 14 has the largest n, almost double that of case 16 despite the fact that the latter has one extra island.
To visualize how this is possible, let's plot the route corresponding to the largest n for each case (though note that there might be multiple possible routes for each case):
figure
tiledlayout('flow','TileSpacing','tight','Padding','tight');
for i = plot_cases
nexttile
hold on
box on
set(gca,{'XTick','YTick'},{[],[]});
% Changing the layout to circular so we can better visualize the paths
p = plot(D{i},'ArrowSize',10,'Layout','Circle');
% Alternatively we could use the XData and YData properties if the positions of the islands were provided
axis([-1.5 1.5 -1.5 1.75])
[row,col] = ind2sub(size(d{i}),id(i));
highlight(p,shortestpath(D{i},row,col),'EdgeColor','r','NodeColor','r','LineWidth',2);
lims = axis;
text(lims(1)+diff(lims(1:2))*0.05,lims(3)+diff(lims(3:4))*0.9,sprintf('n = %d',d{i}(row,col)),'HorizontalAlignment','Left')
end
And busted! Lord Ned has been exposed to be taking advantages of the tectonic forces and has clearly instructed his corrupted civil engineer lackeys to design the bridges to purposely have the visitors go around in circles in order to drain them of their precious savings. In particular, for cases 8 and 9, he would have them go through each single island just to get from a single island to another, whereas for case 14 they would have to visit 8 of the 9 islands just to get to their destination. If that's not diabolical then I don't know what is!
Ned jokes aside, I hope you enjoyed this contest just as much as I did, and that you found this article useful. I look forward to seeing more creative problems and solutions in the future.
It’s exciting to dive into a new dataset full of unfamiliar variables but it can also be overwhelming if you’re not sure where to start. Recently, I discovered some new interactive features in MATLAB live scripts that make it much easier to get an overview of your data. With just a few clicks, you can display sparklines and summary statistics using table variables, sort and filter variables, and even have MATLAB generate the corresponding code for reproducibility.
The Graphics and App Building blog published an article that walks through these features showing how to explore, clean, and analyze data—all without writing any code.
If you’re interested in streamlining your exploratory data analysis or want to see what’s new in live scripts, you might find it helpful:
If you’ve tried these features or have your own tips for quick data exploration in MATLAB, I’d love to hear your thoughts!
Ludvig Nordin
Ludvig Nordin
上次活动时间: 大约 6 小时 前

idris
idris
上次活动时间: 大约 3 小时 前

In the FAQs, I saw the procedure to download the "mobile background", is the the same thing as an award? If yes, good, else how can we get an award and what are the available ones?
iaabdulhameed@knu.ac.kr
idris
idris
上次活动时间: 大约 12 小时 前

Glad to have watched the session, especially the part when the speaker, Arthur gave an answer to my question on "speech recognition use case" in Avionics.
Title: Looking for Internship Guidance as a Beginner MATLAB/Simulink Learner
Hello everyone,
I’m a Computer Science undergraduate currently building a strong foundation in MATLAB and Simulink. I’m still at a beginner level, but I’m actively learning every day and can work confidently once I understand the concepts. Right now I’m focusing on MATLAB modeling, physics simulation, and basic control systems so that I can contribute effectively to my current project.
I’m part of an Autonomous Underwater Vehicle (AUV) team preparing for the Singapore AUV Challenge (SAUVC). My role is in physics simulation, controls, and navigation, and MATLAB/Simulink plays a major role in that pipeline. I enjoy physics and mathematics deeply, which makes learning modeling and simulation very exciting for me.
On the coding side, I practice competitive programming regularly—
Codeforces rating: ~1200
LeetCode rating: ~1500
So I'm comfortable with logic-building and problem solving. What I’m looking for:
I want to know how a beginner like me can start applying for internships related to MATLAB, Simulink, modeling, simulation, or any engineering team where MATLAB is widely used (including companies outside MathWorks).
I would really appreciate advice from the community on:
  • What skills should I strengthen first?
  • Which MATLAB/Simulink toolboxes are most important for beginners aiming toward simulation/control roles?
  • What small projects or portfolio examples should I build to improve my profile?
  • What is the best roadmap to eventually become a good candidate for internships in this area?
Any guidance, resources, or suggestions would be extremely helpful for me.
Thank you in advance to everyone who shares their experience!
Hi everyone!
I’m Kishen Mahadevan, Senior Product Manager at MathWorks, where I focus on controls and deep learning. I’m excited to be speaking at MATLAB EXPO this year!
In one of my sessions, I’ll share how AI-based reduced order models (ROMs) are transforming engineering workflows—using battery fast charging as an example—making it easier to reuse high-fidelity models for real-time control and deployment.
I’d love to have you join the conversation at the EXPO and right here in the community!
Feel free to drop any questions or thoughts ahead of the event.
Jorge Bernal-AlvizJorge Bernal-Alviz shared the following code that requires R2025a or later:
Test()
Warning: Hardware-accelerated graphics is unavailable. Displaying fewer markers to preserve interactivity.
function Test()
duration = 10;
numFrames = 800;
frameInterval = duration / numFrames;
w = 400;
t = 0;
i_vals = 1:10000;
x_vals = i_vals;
y_vals = i_vals / 235;
r = linspace(0, 1, 300)';
g = linspace(0, 0.1, 300)';
b = linspace(1, 0, 300)';
r = r * 0.8 + 0.1;
g = g * 0.6 + 0.1;
b = b * 0.9 + 0.1;
customColormap = [r, g, b];
figure('Position', [100, 100, w, w], 'Color', [0, 0, 0]);
axis equal;
axis off;
xlim([0, w]);
ylim([0, w]);
hold on;
colormap default;
colormap(customColormap);
plothandle = scatter([], [], 1, 'filled', 'MarkerFaceAlpha', 0.12);
for i = 1:numFrames
t = t + pi/240;
k = (4 + 3 * sin(y_vals * 2 - t)) .* cos(x_vals / 29);
e = y_vals / 8 - 13;
d = sqrt(k.^2 + e.^2);
c = d - t;
q = 3 * sin(2 * k) + 0.3 ./ (k + 1e-10) + ...
sin(y_vals / 25) .* k .* (9 + 4 * sin(9 * e - 3 * d + 2 * t));
points_x = q + 30 * cos(c) + 200;
points_y = q .* sin(c) + 39 * d - 220;
points_y = w - points_y;
CData = (1 + sin(0.1 * (d - t))) / 3;
CData = max(0, min(1, CData));
set(plothandle, 'XData', points_x, 'YData', points_y, 'CData', CData);
brightness = 0.5 + 0.3 * sin(t * 0.2);
set(plothandle, 'MarkerFaceAlpha', brightness);
drawnow;
pause(frameInterval);
end
end
Jack and Cleve had famously noted in the "A Preview of PC-MATLAB" in 1985: For those of you that have not experienced MATLAB, we would like to try to show you what everybody is excited about ... The best way to appreciate PC-MATLAB is, of course, to try it yourself.
Try out the end-to-end workflow of developing touchless applications with both MathWorks' tools and STM Dev Cloud from last year!
You can check out the exercises and the manual.
You can also register this year's EXPO. Join the Hands-On workshops to learn the latest features that make the design and deployment workflow even easier!
David
David
上次活动时间: 2025-11-6,20:47

Parallel Computing Onramp is here! This free, one-hour self-paced course teaches the basics of running MATLAB code in parallel using multiple CPU cores, helping users speed up their code and write code that handles information efficiently.
Remember, Onramps are free for everyone - give the new course a try if you're curious. Let us know what you think of it by replying below.
Hey Creative Coders! 😎
Let’s get to know each other. Drop a quick intro below and meet your teammates! This is your chance to meet teammates, find coding buddies, and build connections that make the contest more fun and rewarding!
You can share:
  • Your name or nickname
  • Where you’re from
  • Your favorite coding topic or language
  • What you’re most excited about in the contest
Let’s make Team Creative Coders an awesome community—jump in and say hi! 🚀
Welcome to the Cody Contest 2025 and the Creative Coders team channel! 🎉
You think outside the box. Where others see limitations, you see opportunities for innovation. This is your space to connect with like-minded coders, share insights, and help your team win. To make sure everyone has a great experience, please keep these tips in mind:
  1. Follow the Community Guidelines: Take a moment to review our community standards. Posts that don’t follow these guidelines may be flagged by moderators or community members.
  2. Ask Questions About Cody Problems: When asking for help, show your work! Include your code, error messages, and any details needed to reproduce your results. This helps others provide useful, targeted answers.
  3. Share Tips & Tricks: Knowledge sharing is key to success. When posting tips or solutions, explain how and why your approach works so others can learn your problem-solving methods.
  4. Provide Feedback: We value your feedback! Use this channel to report issues or share creative ideas to make the contest even better.
Have fun and enjoy the challenge! We hope you’ll learn new MATLAB skills, make great connections, and win amazing prizes! 🚀
Get ready to roll up your sleeves at MATLAB EXPO 2025 – our global online event is back, and this year we’re offering 10 hands-on workshops designed to spark innovation and deepen your skills with MATLAB Online and Simulink Online.
Whether you're exploring AI, modeling batteries, or building carbon trackers, these live workshops are your chance to:
  • Work directly in MATLAB and Simulink Online
  • Solve real-world challenges with guidance from MathWorks experts
  • Connect with peers across industries
  • Ask questions and get live feedback
Join the Experience to learn more about each workshop below!
Which workshop are you most excited to attend?!
Day 1:
  • Beyond the Labels: Leveraging AI Techniques for Enlightened Product Choices
  • A Hands-On Introduction to Reinforcement Learning with MATLAB and Simulink
  • Curriculum Development with MATLAB Copilot and Generative AI
  • Simscape Battery Workshop
  • Generating Tests for your MATLAB code
Day 2:
  • Hands-On AI for Smart Appliances: From Sensor Data to Embedded Code
  • A Hands-On Introduction to Reduced Order Modeling with MATLAB and Simulink
  • Introduction to Research Software and Development with Simulink
  • Hack Your Carbon Impact: Build and Publish an Emissions Tracker with MATLAB
  • How to Simulate Scalable Cellular and Connectivity Networks: A Hands-On Session
We look forward to Accelerating the Pace of Engineering and Science together!
It’s an honor to deliver the keynote at MATLAB EXPO 2025. I'll explore how AI changes the game in engineered systems, bringing intelligence to every step of the process from design to deployment. This short video captures a glimpse of what I’ll share:
What excites or challenges you about this shift? Drop a comment or start a thread!
David
David
上次活动时间: 2025-10-20,21:26

I just learned you can access MATLAB Online from the following shortcut in your web browser: https://matlab.new