MATLAB|趣味程序(纯属娱乐)

在网上发现 很多用matlab写的有趣的小程序,整理如下。哈哈,娱乐一下。

著作属于原作者。

Part1:matlab自带的彩蛋

  • 输入:vibes

    • Vibrating L-shaped membrane.
  • 输入:spy

  • 输入:life

  • 输入:penny

  • 输入:why

  • 输入:teapotdemo

    • A demo that uses the famous Newell teapot to demonstrate MATLAB graphics features.
  • 输入:logo

surf(membrane(1))
shading interp
  • 输入:travel

    • Traveling salesman problem demonstration.
  • 输入:life

    • MATLAB’s version of Conway’s Game of Life.
  • 输入:makevase

    • Generate and plot a surface of revolution.
  • 输入:truss

    • Animation of a bending bridge truss.
  • 输入:fifteen

    • A sliding puzzle of fifteen squares and sixteen slots.
  • 输入:xpquad

    • Superquadrics plotting demonstration.
  • 输入:wrldtrv

    • Show great circle flight routes around the globe.

Part2:网络上大家编的有趣的小程序

  • 传递爱的正能量
[x,y]=meshgrid(-10:0.1:10);
z=-(17*x.^2-16*y.*abs(x)+17.*y.^2);
[c,h]=contourf(z,100);set(h,'linestyle','none')
不算是命令吧,一个脑洞很大的英国老师教的一个小script,轻度调教Matlab,打开程序可以显示你想它显示的内容,并且自动把workspace设置到常用路径,这个脚本后来就被大家愉快地玩坏了。
首先写一个script,命名为startup.m
fprintf里面就是你想显示的内容啦,你写hello world也好,keep calm and zhao lanxiang 也罢,都有一种调教自家Matlab的快感。
cd里是你的常用workspace directory
------------------------------------------
%startup.m
fprintf(1,'Hello! This is your beloved Queen MATLAB! \n');
fprintf(1,'Message form start.m\n\n');
fprintf(1,'I would like to torture you even more today-just kidding:)');
fprintf(1,'Reminder:when you add a new function to a tool box, issue command:\n');
fprintf(1,' rehash toolboxcache\n\n');
cd ('~/Documents/MyMath/project');
------------------------------------------
然后!把你存放这个脚本的路径加入Matlab搜索路径里!home-set path-add with subfolder!后生切记!
clf
clear
clc
f=@(x,y,z) x.^2.*z.^3+9*y.^2.*z.^3/80-(x.^2+9*y.^2/4+z.^2-1).^3;%心形曲面函数
[x,y,z]=meshgrid(-1.5:0.1:1.5);%画图范围
v=f(x,y,z);
%画图
h=patch(isosurface(x,y,z,v,0));
isonormals(x,y,z,v,h)
set(h,'FaceColor','r','EdgeColor','none');
title('Programmed By Suksaha  age')
alpha(0.6)   
grid off;
axis([-1.5 1.5 -1.5 1.5 -1.5 1.5])
lighting Gouraud
h = camlight('left');
for i = 1:180;%水平旋转照相机
        camorbit(1,0)
        camlight(h,'left');
        drawnow;
end
  • 酷炫心形:
clf
clear
clc
[x,y]=meshgrid(-10:0.01:10);
z=-(17*x.^2-16*y.*abs(x)+17.*y.^2);
[c,h]=contourf(z,100);
set(h,'linestyle','none')
axis off
legend('bi simbe buyelembi, mini boobai')
    原文作者:云飘飘同学
    原文地址: https://www.jianshu.com/p/c8f85e2cf334
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞