Contenu principal

Résultats pour

Zhaoxu Liu / slandarer
Zhaoxu Liu / slandarer
Dernière activité environ 19 heures il y a

Generate a 3D visualization of carnation flowers
with sepals and stems for celebrating Mother's Day 2026.
function carnation
% CARNATION Generate a 3D visualization of carnation flowers with sepals and stems.
% This code is authored by Zhaoxu Liu / slandarer
% for the purpose of celebrating Mother's Day 2026.
% =========================================================================
% Zhaoxu Liu / slandarer (2026). carnation for Mother's Day
% (https://www.mathworks.com/matlabcentral/fileexchange/183838-carnation-for-mother-s-day),
% MATLAB Central File Exchange. Retrieved May 9, 2026.
% Create figure and axes / 创建图窗及坐标区域
fig = figure('Units','normalized', 'Position',[.3,.1,.4,.8],'Color',[244,234,225]./255);
axes('Parent',fig, 'NextPlot','add', 'DataAspectRatio',[1,1,1],...
'View',[-64, 5.5], 'Position',[0,-.15,1,1], 'Color',[244,234,225]./255, ...
'XColor','none', 'YColor','none', 'ZColor','none');
annotation("textbox", [.05, .8, .9, .2], "String", {"Happy"; "Mother's Day"}, ...
'FontName','Segoe Script', 'FontSize',52, 'FontWeight','bold', 'EdgeColor','none', ...
'HorizontalAlignment','center', 'VerticalAlignment','middle', 'Color',[97,40,20]./255);
xx = linspace(0, 1, 100);
tt = linspace(0, 1, 1e4);
[X, P] = meshgrid(xx, tt);
T1 = P*20*pi;
C1 = 1 - (1 - mod(3.6*T1/pi, 2)).^4./2; % Petal profile / 花瓣形状
S1 = (sin(50*T1)/150 + sin(10*T1)/30).*min(1, max(0, (X - .85)/.1)); % Edge serration / 边缘褶皱和锯齿
Y1 = (- (X.*1.2 - .5).^5.*32 - 1)./15.*P; % Petal curvature / 花瓣弧度
% Petal shape and serration modeling + rotating the planar petal to tilt it
% 花瓣形状和锯齿塑造 + 转动平躺的花瓣令其倾斜
R1 = (C1 + S1).*(X.*sin(P) - Y1.*cos(P))./(P + .5);
H1 = (C1 + S1).*(X.*cos(P) + Y1.*sin(P));
% Convert radius to Cartesian coordinates / 将半径映射为X,Y坐标
X1 = R1.*cos(T1);
Y1 = R1.*sin(T1);
% Colormap for carnation petals / 康乃馨配色
CList1 = [208, 62, 23; 221,146,121; 229,201,202; 233,219,222; 237,223,225]./255;
CMat1 = zeros(1e4, 100, 3);
CMat1(:, :, 1) = repmat(interp1(linspace(0, 1, size(CList1, 1)), CList1(:, 1), linspace(0, 1, 100)), [1e4, 1]);
CMat1(:, :, 2) = repmat(interp1(linspace(0, 1, size(CList1, 1)), CList1(:, 2), linspace(0, 1, 100)), [1e4, 1]);
CMat1(:, :, 3) = repmat(interp1(linspace(0, 1, size(CList1, 1)), CList1(:, 3), linspace(0, 1, 100)), [1e4, 1]);
% Darken edges / 边缘的深色
for i = 1:1e4
tNum = randi([98, 100]);
CMat1(i, tNum:end, 1) = 212./255;
CMat1(i, tNum:end, 2) = 87./255;
CMat1(i, tNum:end, 3) = 113./255;
end
% Rotation matrices / 旋转矩阵
Rx = @(rx) [1, 0, 0; 0, cos(rx), -sin(rx); 0, sin(rx), cos(rx)];
Rz = @(yz) [cos(yz), - sin(yz), 0; sin(yz), cos(yz), 0; 0, 0, 1];
Rx1 = Rx(pi/6); Rz1 = Rz(0);
% Render flower / 绘制康乃馨
surface(X1, Y1, H1 + .3, 'CData',CMat1, 'EdgeAlpha',0.1, 'EdgeColor',[224,39,39]./255, 'FaceColor','interp')
[U1, V1, W1] = matRotate(X1, Y1, H1 + .3, Rx1);
surface(U1 + .7, V1 - .7, W1 - .6, 'CData',CMat1, 'EdgeAlpha',0.1, 'EdgeColor',[224,39,39]./255, 'FaceColor','interp')
% Following the same method as before,
% the profile is designed with four serrated cycles to simulate the four sepals.
% 还是之前的方法,不过让轮廓有4个锯齿状周期来模拟四片花萼
% Sepals generation with 4-lobed pattern / 生成四片花萼(带4个锯齿状周期)
[X, T] = meshgrid(linspace(0, 1, 100), linspace(0, 1, 100).*2*pi);
P2 = T.*0 + pi/8;
C2 = .5 + (.5 - abs(mod(T, pi/2)/pi*2 - .5))*.4;
Y2 = (- (X.*1 - .5).^7.*128 - 1)./15 - .1;
R2 = C2.*(X.*sin(P2) - Y2.*cos(P2));
H2 = C2.*(X.*cos(P2) + Y2.*sin(P2));
X2 = R2.*cos(T);
Y2 = R2.*sin(T);
% Rotate by 90 degrees around the z-axis
% and reduce the size to render the four smaller sepals.
% 绕z轴旋转90度且减小其大小,绘制四片小花萼
% Smaller sepal layer / 绘制四片小花萼(第二层)
P3 = T.*0 + pi/10;
C3 = .3 + (.5 - abs(mod(T + pi/4, pi/2)/pi*2 - .5))*.7;
Y3 = (- (X.*.7 - .5).^7.*128 - 1)./15 - .1;
R3 = C3.*(X.*sin(P3) - Y3.*cos(P3));
H3 = C3.*(X.*cos(P3) + Y3.*sin(P3));
X3 = R3.*cos(T);
Y3 = R3.*sin(T);
% Colormap for sepals / 花托配色
CList2 = [178,173,113; 151,135, 73; 117,123, 50; 86, 89, 29; 75, 65, 17]./255;
CMat2 = zeros(100, 100, 3);
CMat2(:, :, 1) = repmat(interp1(linspace(0, 1, size(CList2, 1)), CList2(:, 1), linspace(0, 1, 100)), [100, 1]);
CMat2(:, :, 2) = repmat(interp1(linspace(0, 1, size(CList2, 1)), CList2(:, 2), linspace(0, 1, 100)), [100, 1]);
CMat2(:, :, 3) = repmat(interp1(linspace(0, 1, size(CList2, 1)), CList2(:, 3), linspace(0, 1, 100)), [100, 1]);
% Render sepals / 绘制花托
surf(X2, Y2, H2.*.8 + .12, 'CData',CMat2, 'EdgeAlpha',0.1, 'EdgeColor',CList2(end,:), 'FaceColor','interp')
surf(X3.*.93, Y3.*.92, H3.*.5 + .02, 'FaceColor',[ 84, 85, 54]./255, 'EdgeAlpha',0.1, 'EdgeColor','k')
[U2, V2, W2] = matRotate(X2, Y2, H2.*.8 + .12, Rx1);
[U3, V3, W3] = matRotate(X3.*.93, Y3.*.92, H3.*.5 + .02, Rx1);
surf(U2 + .7, V2 - .7, W2 - .6, 'CData',CMat2, 'EdgeAlpha',0.1, 'EdgeColor',CList2(end,:), 'FaceColor','interp')
surf(U3 + .7, V3 - .7, W3 - .6, 'FaceColor',[ 84, 85, 54]./255, 'EdgeAlpha',0.1, 'EdgeColor','k')
% A pulse function with two periods is applied
% to the contour to simulate the leaves.
% 让轮廓有2个周期且是脉冲函数,来模拟叶片
P4 = T.*0 + pi/16;
C4 = - abs(mod(T, pi)/pi - .5) + .11;
C4(C4 < 0) = 0; C4 = C4.*10; C4(51:100, :) = C4(51:100, :).*.7;
Y4 = (- (X.*1.01 - .5).^7.*128 - 1)./15 - .03;
R4 = C4.*(X.*sin(P4) - Y4.*cos(P4));
H4 = C4.*(X.*cos(P4) + Y4.*sin(P4));
X4 = R4.*cos(T);
Y4 = R4.*sin(T);
surf(X4 - .1, Y4 + .05, H4 - 2.2, 'FaceColor',[ 84, 85, 54]./255, 'EdgeAlpha',0.1, 'EdgeColor','k')
[U4, V4, W4] = matRotate(X4 - .1, Y4 - .1, H4 + .1, Rz1);
[U4, V4, W4] = matRotate(U4, V4, W4, Rx1);
surf(U4 + .7, V4 - .7 + 1, W4 - .6 - 1.2, 'FaceColor',[ 84, 85, 54]./255, 'EdgeAlpha',0.1, 'EdgeColor','k')
P5 = T.*0 + pi/8;
C5 = - abs(mod(T + pi/6, pi)/pi - .5) + .11;
C5(C5 < 0) = 0; C5 = C5.*5;
Y5 = (- (X.*1.01 - .5).^7.*128 - 1)./15 - .1;
R5 = C5.*(X.*sin(P5) - Y5.*cos(P5));
H5 = C5.*(X.*cos(P5) + Y5.*sin(P5));
X5 = R5.*cos(T);
Y5 = R5.*sin(T);
surf(X5, Y5, H5 - .3, 'FaceColor',[ 84, 85, 54]./255, 'EdgeAlpha',0.1, 'EdgeColor','k')
[U5, V5, W5] = matRotate(X5, Y5, H5+.1, Rx1);
surf(U5 + .7, V5 - .7 + 1/4, W5 - .6 - 1.7/4, 'FaceColor',[ 84, 85, 54]./255, 'EdgeAlpha',0.1, 'EdgeColor','k')
% Render stems / 绘制花杆
P1_1 = [mean(X3(:).*.93), mean(Y3(:).*.92), mean(H3(:).*.5 + .02)];
P1_2 = [mean(X5(:)), mean(Y5(:)), mean(H5(:) - .3)];
P1_3 = [mean(X4(:) - .1), mean(Y4(:) + .05), mean(H4(:) - 2.2)];
P1_3 = (P1_3 - P1_2).*1.4 + P1_2;
[XX1, YY1, ZZ1] = cylinderXYZ(P1_1, P1_2, .05);
[XX2, YY2, ZZ2] = cylinderXYZ(P1_2, P1_3, .04);
surf(XX1, YY1, ZZ1, 'FaceColor',[ 84, 85, 54]./255, 'EdgeAlpha',0.1, 'EdgeColor','k')
surf(XX2, YY2, ZZ2, 'FaceColor',[ 84, 85, 54]./255, 'EdgeAlpha',0.1, 'EdgeColor','k')
P1_1 = [mean(U3(:) + .7), mean(V3(:) - .7), mean(W3(:) - .6)];
P1_2 = [mean(U5(:) + .7), mean(V5(:) - .7 + 1/4), mean(W5(:) - .6 - 1.7/4)];
P1_3 = [mean(U4(:) + .7), mean(V4(:) - .7 + 1), mean(W4(:) - .6 - 1.2)];
P1_3 = (P1_3 - P1_2).*2.4 + P1_2;
[XX1, YY1, ZZ1] = cylinderXYZ(P1_1, P1_2, .05);
[XX2, YY2, ZZ2] = cylinderXYZ(P1_2, P1_3, .04);
surf(XX1, YY1, ZZ1, 'FaceColor',[ 84, 85, 54]./255, 'EdgeAlpha',0.1, 'EdgeColor','k')
surf(XX2, YY2, ZZ2, 'FaceColor',[ 84, 85, 54]./255, 'EdgeAlpha',0.1, 'EdgeColor','k')
% 在任意两点间构建圆柱
function [XX, YY, ZZ] = cylinderXYZ(P1, P2, r)
% CYLINDERXYZ Create a cylinder connecting two 3D points
% [XX, YY, ZZ] = cylinderXYZ(P1, P2, r) generates a cylinder
% of radius r between points P1 and P2.
v = P2 - P1; l = norm(v);
if l < eps, return; end
[XX, YY, ZZ] = cylinder(r, 30); ZZ = ZZ * l;
ddir = [0, 0, 1]; tdir = v / l;
if dot(ddir, tdir) > 0.9999
R = eye(3);
elseif dot(ddir, tdir) < -0.9999
R = [1, 0, 0; 0, -1, 0; 0, 0, -1];
else
av = cross(ddir, tdir); av = av / norm(av);
R = axisRotate(av, acos(dot(ddir, tdir)));
end
for ii = 1:size(XX, 1)
for jj = 1:size(XX, 2)
p = R * [XX(ii, jj); YY(ii, jj); ZZ(ii, jj)];
XX(ii, jj) = p(1) + P1(1);
YY(ii, jj) = p(2) + P1(2);
ZZ(ii, jj) = p(3) + P1(3);
end
end
end
% 通过矩阵旋转数据
function [U, V, W] = matRotate(X, Y, Z, R)
% MATROTATE Apply 3x3 rotation matrix to a set of 3D points
% [U,V,W] = matRotate(X,Y,Z,R) rotates points (X,Y,Z)
% using rotation matrix R.
U = X; V = Y; W = Z;
for ii = 1:numel(X)
v = [X(ii); Y(ii); Z(ii)];
n = R*v; U(ii) = n(1); V(ii) = n(2); W(ii) = n(3);
end
end
% 根据轴-角参数生成旋转矩阵
function R = axisRotate(axis, angle)
% AXISROTATE Compute rotation matrix from axis-angle representation
% R = axisRotate(axis, angle) returns a 3x3 rotation matrix
% for rotating by angle (radians) around the given axis vector.
% Implementation based on Rodrigues' rotation formula.
u = axis(1); v = axis(2); w = axis(3);
c = cos(angle); s = sin(angle);
R = [u^2 + (1-u^2)*c, u*v*(1-c) - w*s, u*w*(1-c) + v*s;
u*v*(1-c) + w*s, v^2 + (1-v^2)*c, v*w*(1-c) - u*s;
u*w*(1-c) - v*s, v*w*(1-c) + u*s, w^2 + (1-w^2)*c];
end
end
We’re excited to share that Cleve Moler, creator of MATLAB, has been elected to the U.S. National Academy of Sciences—one of the highest honors in science.
This recognition celebrates Cleve’s groundbreaking contributions to numerical computing and his lasting impact on researchers, educators, and engineers around the world. From advancing numerical linear algebra to making powerful computation more accessible through MATLAB, his work has shaped how science and engineering are done today.
Please join us in congratulating Cleve on this well‑deserved honor!
🔗 Learn more about the 2026 NAS election
Hello Community,
Registration is now open for the MathWorks Automotive Conference 2026 North America. Join industry leaders and MathWorks experts to learn about the latest trends in:
  • Software-defined vehicles
  • Generative AI
  • Virtual vehicles
  • AI and machine learning
Event details
  • Date: April 28, 2026
  • Location: Saint John’s Resort, Plymouth, MI
This conference is a great opportunity to connect with MathWorks and industry peers—and to explore what’s next in automotive engineering. We encourage you to register today.
We hope to see you there.
Chen Lin
Chen Lin
Dernière activité le 28 Jan 2026

A coworker shared with me a hilarious Instagram post today. A brave bro posted a short video showing his MATLAB code… casually throwing 49,000 errors!
Surprisingly, the video went virial and recieved 250,000+ likes and 800+ comments. You really never know what the Instagram algorithm is thinking, but apparently “my code is absolutely cooked” is a universal developer experience 😂
Last note: Can someone please help this Bro fix his code?
Chen Lin
Chen Lin
Dernière activité le 28 Jan 2026

In 2025, we saw the growing impact of GenAI on site traffic and user behavior across the entire technical landscape. Amid all this change, MATLAB Central continued to stand out as a trusted home for MATLAB and Simulink users. More than 11 million unique visitors in 2025 came to MATLAB Central to ask questions, share code, learn, and connect with one another.
Let’s celebrate what made 2025 memorable across three key areas: people, content, and events.
People
In 2025, nearly 20,000 contributors participated across the community. We’d like to spotlight a few standout contributors:
  • @Sam Chak earned the Most Accepted Answers Badge for both 2024 and 2025. Sam is a rising star in MATLAB Answers with 2,000+ answers and 1,000+ votes.
  • @Rodney Tan has been actively contributing files to File Exchange. In 2025, his submissions got almost 20,000 downloads!
  • @Dyuman Joshi was recognized as a top contributor on both Cody and Answers. Many may not know that Dyuman is also a Cody moderator, doing tremendous behind-the-scenes moderation work to keep the platform running smoothly.
  • A warm welcome to @Steve Eddins, who joined the Community Advisory Board. Steve brings a unique perspective as a former MathWorker and long-time top community contributor.
  • Congratulations to @Walter Roberson on reaching 100 followers! MATLAB Central thrives on people-to-people connections, and we’d love to see even more of these relationships grow.
Of course, there are many contributors we didn’t mention here—thank you all for your outstanding contributions and for making the community what it is.
Content
Our high-quality community content not only attracts users but also helps power the broader GenAI ecosystem.
Popular Blog Post & File Exchange Submission
Popular Discussion Post
  • What did MATLAB/Simulink users wait for most in 2025? It's R2025a! Where is MATLAB R2025a? became the most-viewed discussion post, with 10,000 views and 30 comments. Thanks for your patience — MATLAB R2025a turned out to be one of the biggest releases we’ve ever delivered.
Most Viewed Question
  • How do I create a for loop in MATLAB? was the most-viewed community question of the year. It’s a fun reminder that even as MATLAB evolves, the basics remain essential — and always in demand.
Most Voted Poll
Events
The Cody Contest 2025 brought teams together to tackle challenging but fun Cody problems. During the contest:
  • 20,000+ solutions were submitted
  • 20+ tips & tricks articles were shared by top players
While the contest has ended, you can still challenge yourself with the fun contest problem group. If you get stuck, the tips & tricks articles are a great resource—and you’ll be amazed by the creativity and skill of the contributors.
Thank you for being part of an incredible 2025. Your curiosity, generosity, and expertise are what make MATLAB Central a trusted home for millions—and we look forward to learning and growing together in 2026.
Give your LLM an easier time looking for information on mathworks.com: point it to the recently released llms.txt files. The top-level one is www.mathworks.com/llms.txt, release changes use www.mathworks.com/help/relnotes. How does it work for you??
Walter Roberson
Walter Roberson
Dernière activité le 11 Déc 2025

I can't believe someone put time into this ;-)
The formula comes from @yuruyurau. (https://x.com/yuruyurau)
digital life 1
figure('Position',[300,50,900,900], 'Color','k');
axes(gcf, 'NextPlot','add', 'Position',[0,0,1,1], 'Color','k');
axis([0, 400, 0, 400])
SHdl = scatter([], [], 2, 'filled','o','w', 'MarkerEdgeColor','none', 'MarkerFaceAlpha',.4);
t = 0;
i = 0:2e4;
x = mod(i, 100);
y = floor(i./100);
k = x./4 - 12.5;
e = y./9 + 5;
o = vecnorm([k; e])./9;
while true
t = t + pi/90;
q = x + 99 + tan(1./k) + o.*k.*(cos(e.*9)./4 + cos(y./2)).*sin(o.*4 - t);
c = o.*e./30 - t./8;
SHdl.XData = (q.*0.7.*sin(c)) + 9.*cos(y./19 + t) + 200;
SHdl.YData = 200 + (q./2.*cos(c));
drawnow
end
digital life 2
figure('Position',[300,50,900,900], 'Color','k');
axes(gcf, 'NextPlot','add', 'Position',[0,0,1,1], 'Color','k');
axis([0, 400, 0, 400])
SHdl = scatter([], [], 2, 'filled','o','w', 'MarkerEdgeColor','none', 'MarkerFaceAlpha',.4);
t = 0;
i = 0:1e4;
x = i;
y = i./235;
e = y./8 - 13;
while true
t = t + pi/240;
k = (4 + sin(y.*2 - t).*3).*cos(x./29);
d = vecnorm([k; e]);
q = 3.*sin(k.*2) + 0.3./k + sin(y./25).*k.*(9 + 4.*sin(e.*9 - d.*3 + t.*2));
SHdl.XData = q + 30.*cos(d - t) + 200;
SHdl.YData = 620 - q.*sin(d - t) - d.*39;
drawnow
end
digital life 3
figure('Position',[300,50,900,900], 'Color','k');
axes(gcf, 'NextPlot','add', 'Position',[0,0,1,1], 'Color','k');
axis([0, 400, 0, 400])
SHdl = scatter([], [], 1, 'filled','o','w', 'MarkerEdgeColor','none', 'MarkerFaceAlpha',.4);
t = 0;
i = 0:1e4;
x = mod(i, 200);
y = i./43;
k = 5.*cos(x./14).*cos(y./30);
e = y./8 - 13;
d = (k.^2 + e.^2)./59 + 4;
a = atan2(k, e);
while true
t = t + pi/20;
q = 60 - 3.*sin(a.*e) + k.*(3 + 4./d.*sin(d.^2 - t.*2));
c = d./2 + e./99 - t./18;
SHdl.XData = q.*sin(c) + 200;
SHdl.YData = (q + d.*9).*cos(c) + 200;
drawnow; pause(1e-2)
end
digital life 4
figure('Position',[300,50,900,900], 'Color','k');
axes(gcf, 'NextPlot','add', 'Position',[0,0,1,1], 'Color','k');
axis([0, 400, 0, 400])
SHdl = scatter([], [], 1, 'filled','o','w', 'MarkerEdgeColor','none', 'MarkerFaceAlpha',.4);
t = 0;
i = 0:4e4;
x = mod(i, 200);
y = i./200;
k = x./8 - 12.5;
e = y./8 - 12.5;
o = (k.^2 + e.^2)./169;
d = .5 + 5.*cos(o);
while true
t = t + pi/120;
SHdl.XData = x + d.*k.*sin(d.*2 + o + t) + e.*cos(e + t) + 100;
SHdl.YData = y./4 - o.*135 + d.*6.*cos(d.*3 + o.*9 + t) + 275;
SHdl.CData = ((d.*sin(k).*sin(t.*4 + e)).^2).'.*[1,1,1];
drawnow;
end
digital life 5
figure('Position',[300,50,900,900], 'Color','k');
axes(gcf, 'NextPlot','add', 'Position',[0,0,1,1], 'Color','k');
axis([0, 400, 0, 400])
SHdl = scatter([], [], 1, 'filled','o','w',...
'MarkerEdgeColor','none', 'MarkerFaceAlpha',.4);
t = 0;
i = 0:1e4;
x = mod(i, 200);
y = i./55;
k = 9.*cos(x./8);
e = y./8 - 12.5;
while true
t = t + pi/120;
d = (k.^2 + e.^2)./99 + sin(t)./6 + .5;
q = 99 - e.*sin(atan2(k, e).*7)./d + k.*(3 + cos(d.^2 - t).*2);
c = d./2 + e./69 - t./16;
SHdl.XData = q.*sin(c) + 200;
SHdl.YData = (q + 19.*d).*cos(c) + 200;
drawnow;
end
digital life 6
clc; clear
figure('Position',[300,50,900,900], 'Color','k');
axes(gcf, 'NextPlot','add', 'Position',[0,0,1,1], 'Color','k');
axis([0, 400, 0, 400])
SHdl = scatter([], [], 2, 'filled','o','w', 'MarkerEdgeColor','none', 'MarkerFaceAlpha',.4);
t = 0;
i = 1:1e4;
y = i./790;
k = y; idx = y < 5;
k(idx) = 6 + sin(bitxor(floor(y(idx)), 1)).*6;
k(~idx) = 4 + cos(y(~idx));
while true
t = t + pi/90;
d = sqrt((k.*cos(i + t./4)).^2 + (y/3-13).^2);
q = y.*k.*cos(i + t./4)./5.*(2 + sin(d.*2 + y - t.*4));
c = d./3 - t./2 + mod(i, 2);
SHdl.XData = q + 90.*cos(c) + 200;
SHdl.YData = 400 - (q.*sin(c) + d.*29 - 170);
drawnow; pause(1e-2)
end
digital life 7
clc; clear
figure('Position',[300,50,900,900], 'Color','k');
axes(gcf, 'NextPlot','add', 'Position',[0,0,1,1], 'Color','k');
axis([0, 400, 0, 400])
SHdl = scatter([], [], 2, 'filled','o','w', 'MarkerEdgeColor','none', 'MarkerFaceAlpha',.4);
t = 0;
i = 1:1e4;
y = i./345;
x = y; idx = y < 11;
x(idx) = 6 + sin(bitxor(floor(x(idx)), 8))*6;
x(~idx) = x(~idx)./5 + cos(x(~idx)./2);
e = y./7 - 13;
while true
t = t + pi/120;
k = x.*cos(i - t./4);
d = sqrt(k.^2 + e.^2) + sin(e./4 + t)./2;
q = y.*k./d.*(3 + sin(d.*2 + y./2 - t.*4));
c = d./2 + 1 - t./2;
SHdl.XData = q + 60.*cos(c) + 200;
SHdl.YData = 400 - (q.*sin(c) + d.*29 - 170);
drawnow; pause(5e-3)
end
digital life 8
clc; clear
figure('Position',[300,50,900,900], 'Color','k');
axes(gcf, 'NextPlot','add', 'Position',[0,0,1,1], 'Color','k');
axis([0, 400, 0, 400])
SHdl{6} = [];
for j = 1:6
SHdl{j} = scatter([], [], 2, 'filled','o','w', 'MarkerEdgeColor','none', 'MarkerFaceAlpha',.3);
end
t = 0;
i = 1:2e4;
k = mod(i, 25) - 12;
e = i./800; m = 200;
theta = pi/3;
R = [cos(theta) -sin(theta); sin(theta) cos(theta)];
while true
t = t + pi/240;
d = 7.*cos(sqrt(k.^2 + e.^2)./3 + t./2);
XY = [k.*4 + d.*k.*sin(d + e./9 + t);
e.*2 - d.*9 - d.*9.*cos(d + t)];
for j = 1:6
XY = R*XY;
SHdl{j}.XData = XY(1,:) + m;
SHdl{j}.YData = XY(2,:) + m;
end
drawnow;
end
digital life 9
clc; clear
figure('Position',[300,50,900,900], 'Color','k');
axes(gcf, 'NextPlot','add', 'Position',[0,0,1,1], 'Color','k');
axis([0, 400, 0, 400])
SHdl{14} = [];
for j = 1:14
SHdl{j} = scatter([], [], 2, 'filled','o','w', 'MarkerEdgeColor','none', 'MarkerFaceAlpha',.1);
end
t = 0;
i = 1:2e4;
k = mod(i, 50) - 25;
e = i./1100; m = 200;
theta = pi/7;
R = [cos(theta) -sin(theta); sin(theta) cos(theta)];
while true
t = t + pi/240;
d = 5.*cos(sqrt(k.^2 + e.^2) - t + mod(i, 2));
XY = [k + k.*d./6.*sin(d + e./3 + t);
90 + e.*d - e./d.*2.*cos(d + t)];
for j = 1:14
XY = R*XY;
SHdl{j}.XData = XY(1,:) + m;
SHdl{j}.YData = XY(2,:) + m;
end
drawnow;
end
The challenge:
You are given a string of lowercase letters 'a' to 'z'.
Each character represents a base-26 digit:
  • 'a' = 0
1. Understand the Base-26 Conversion Process:
Let the input be s = 'aloha'.
Convert each character to a digit:
digits = double(s) - double('a');
This works because:
double('a') = 97
double('b') = 98
So:
double('a') - 97 = 0
double('l') - 97 = 11
double('o') - 97 = 14
double('h') - 97 = 7
double('a') - 97 = 0
Now you have:
[0 11 14 7 0]
2. Interpret as Base-26:
For a number with n digits:
d1 d2 d3 ... dn
Value = d1*26^(n-1) + d2*26^(n-2) + ... + dn*26^0
So for 'aloha' (5 chars):
0*26^4 + 11*26^3 + 14*26^2 + 7*26^1 + 0*26^0
MATLAB can compute this automatically.
3. Avoid loops — Use MATLAB vectorization:
You can compute the weighted sum using dot
digits = double(s) - 'a';
powers = 26.^(length(s)-1:-1:0);
result = dot(digits, powers);
This is clean, short, and vectorized.
4.Test with the examples:
char2num26('funfunfun')
→ 1208856210289
char2num26('matlab')
→ 142917893
char2num26('nasa')
→ 228956
To track the current leader after each match, you can use cumulative scores. First, calculate the cumulative sum for each player across the matches. Then, after eaayer with the highest score.
Hint: Use cumsum(S, 1) to get cumulative scores along the rows (matches). Loop through each row to keep track of the leader. If multiple players tie, pick the lowest index.
Example:
If S = [5 3 4; 2 6 2; 3 5 7], after match 3, the cumulative scores are [10 14 13]. Player 2 leads with 14 hilbs.
This method keeps your code clean and avoids repeatedly summing rows.
Matt Tearle
Matt Tearle
Dernière activité le 26 Nov 2025

Congratulations to all the Cool Coders who have completed the problem set. I hope you weren't too cool to enjoy the silliness I put into the problems.
If you've solved the whole problem set, don't forget to help out your teammates with suggestions, tips, tricks, etc. But also, just for fun, I'm curious to see which of my many in-jokes and nerdy references you noticed. Many of the problems were inspired by things in the real world, then ported over into the chaotic fantasy world of Nedland.
I guess I'll start with the obvious real-world reference: @Ned Gulley (I make no comment about his role as insane despot in any universe, real or otherwise.)
Athi
Athi
Dernière activité le 17 Nov 2025

Extracting the digits of a number will be useful to solve many Cody problems.
Instead of iteratively dividing by 10 and taking the remainder, the digits of a number can be easily extracted using String operations.
%Extract the digits of N
N = 1234;
d = num2str(N)-'0';
d =
1 2 3 4
Cephas
Cephas
Dernière activité le 17 Nov 2025

Instead of looping with if-statements, use logical indexing:
A(A < 0) = 0;
One line, no loops, full clarity.
Cephas
Cephas
Dernière activité le 17 Nov 2025

Whenever a problem repeats in cycles (like indexing or angles), mod() keeps your logic clean:
idx = mod(i-1, n) + 1;
No if-else chaos!
The toughest problem in the Cody Contest 2025 is Clueless - Lord Ned in the Game Room. Thank you Matt Tearle for such as wonderful problem. We can approach this clueless(!) tough problem systematically.
Initialize knowledge Matrix
Based on the hints provided in the problem description, we can initialize a knowledge matrix of size n*3 by m+1. The rows of the knowledge matrix represent the different cards and the columns represent the players. In the knowledge matrix, the first n rows represent category 1 cards, the next n rows, category 2 and the next category 3. We can initialize this matrix with zeros. On the go, once we know that a player holds the card, we can make that entry as 1 and if a player doesn't have the card, we can make that entry as -1.
yourcards processing
These are cards received by us.
  1. In the knowledge matrix, mark the entries as 1 for the cards received. These entries will be the some elements along the column pnum of the knowledge matrix.
  2. Mark all other entries along the column pnum as -1, as we don't receive other cards.
  3. Mark all other entries along the rows corresponding to the received cards as -1, as other players cannot receive the cards that are with us.
commoncards processing
These are the common cards kept open.
  1. In the knowledge matrix, mark the entries as 1 for the common cards. These entries will be some elements along the column (m+1) of the knowledge matrix.
  2. Mark all other entries along the column (m+1) as -1, as other cards are not common.
  3. Mark all other entries along the rows corresponding to the common cards as -1, as other players cannot receive the cards that are common.
Result -1 processing
In the turns input matrix, the result (5th column) value -1 means, the corresponding player doesn't have the 3 cards asked.
  1. Find all the rows with result as -1.
  2. For those corresponding players (1st element in each row of turns matrix), mark -1 entries in the knowledge matrix for those 3 absent cards.
pnum turns processing
These are our turns, so we get definite answers for the asked cards. Make sure to traverse only the rows corresponding to our turn.
  1. The results with -1 are already processed in the previous step.
  2. The results other than -1 means, that particular card is present with the asked player. So mark the entry as 1 for the corresponding player in the knowledge matrix.
  3. Mark all other entries along the row corresponding to step 2 as -1, as other players cannot receive this card.
Result 0 processing
So far, in the yourcards processing, commoncards processing, result -1 processing and pnum turns processing, we had very straightforward definite knowledge about the presence/absence of the card with a player. This step onwards, the tricky part of the problem begins.
result 0 means, any one (or more) of the asked cards are present with the asked player. We don't know exactly which card.
  1. For the asked player, if we have a definite no answer (-1 value in the knowledge matrix) for any two of the three asked cards, then we are sure about the card that is present with the player.
  2. Mark the entry as 1 for the definitely known card for the corresponding player in the knowledge matrix.
  3. Mark all other entries along the row corresponding to step 2 as -1, as other players cannot receive this card.
Cards per Player processing
Based on the number of cards present in the yourcards, we know the ncards, the number of cards per player.
Check along each column of the knowledge matrix, that is for each player.
  1. If the number of ones (definitely present cards) is equal to ncards, we can make all other entries along the column as -1, as this player cannot have any other card.
  2. If the sum of number of ones (definitely present cards) and the number of zeros (unknown cards) is equal to ncards, we can (i) mark the zero entries as one, as the unknown cards have become definitely present cards, (ii) mark all other entries along the column as -1, as other players cannot have any other card.
Category-wise cards checking
For each category, we must get a definite card to be present in the envelope.
  1. In each category (For every group of n rows of knowledge matrix), check for a row with all -1s. That is a card which is definitely not present with any of the players. Then this card will surely be present in the envelope. Add it to the output.
  2. If we could not find an all -1 row, then in that category, check each row for a 1 to be present. Note down the rows which doesn't have a 1. Those cards' players are still unknown. If we have only one such row (unknown card), then it must be in the envelope, as from each category one card is present in the envelope. Add it to the output.
  3. For the card identified in Step 2, mark all the entries along that row in the knowledge matrix as -1, as this card doesn't belong to any player.
Looping Over
In our so far steps, we could note that, the knowledge matrix got updated even after "Result 0 processing" step. This updation in the knowledge matrix may help the "Result 0 processing" step, if we perform it again. So, we can loop over the steps, "Result 0 processing", "Cards per Player processing" and "Category-wise cards checking" again. This ensures that, we will get the desired number of envelop cards (three in our case) as output.
Hoping to see, many of you to finish Cody Contest 2025 and make our team win the trophy.
Cephas
Cephas
Dernière activité le 13 Nov 2025

Instead of growing arrays inside a loop, preallocate with zeros(), ones(), or nan(). It avoids memory fragmentation and speeds up Cody solutions.
A = zeros(1,1000);
Cody often hides subtle hints in example outputs — like data shape, rounding, or format. Matching those exactly saves you a lot of debugging time.
Ludvig Nordin
Ludvig Nordin
Dernière activité le 13 Nov 2025

Pure Matlab
82%
Simulink
18%
11 votes
Cephas
Cephas
Dernière activité le 12 Nov 2025

isequal() is your best friend for Cody! It compares arrays perfectly without rounding errors — much safer than == for matrix outputs.
Cephas
Cephas
Dernière activité le 12 Nov 2025

When Cody hides test cases, test your function with random small inputs first. If it works for many edge cases, it will almost always pass the grader.