標籤:

matlab中有哪些有趣的命令?

比如說,我在command窗口輸入「xpbombs」然後回車運行就會跳出一個掃雷遊戲的小程序,

或者輸入「vibes」運行就會跳出一個膜振動的動畫,還可以調節快慢

嗯,就是這種的


介紹一個歷史挺久的MATLAB彩蛋。

很多人都知道輸入

image

會看到一個小男孩,很多人知道的就到此為止了,不過這個彩蛋沒有到此為止,這張圖片里還隱藏著另外14張圖片,這些圖片都隱藏在這個小男孩的圖片數據中:

這是前幾張,前兩種是MathWorks的員工的寵物,第三張是3階希爾伯特方陣的逆矩陣,第四張MathWorks的早起的logo,如果有興趣的話可以讀一下開發者的博客,裡邊有介紹得到這些圖片的方法和圖片相關的信息

The Story Behind the MATLAB Default Image


另外,試試:

spy

earthmap

cplxdemo :複雜的XYZ立體圖形~黎曼曲面的平面效果

lorenz : Lorenz吸引子動畫顯示我比較喜歡的一個是pretty()

效果如下:


無所不能的Matlab!!

=================================================

①五星紅旗迎風飄揚

=================我是源碼分割線=======================

function varargout=saxplaxliu(varargin)

x=[0 0 40 40 0];
y=[0 13 13 0 0];
k=40/13;
fill(x,y,"r")
hold on
plot(x,y,"r")
axis([0 40 0 13])
seta=pi/6;
R=1.5;R2=0.55;x0=7;y0=9;seta=0;
fliu(R,R2,x0,y0,seta,k)
R=0.6;R2=0.23;x0=15;y0=11.6;seta=-pi/20;
fliu(R,R2,x0,y0,seta,k)
R=0.6;R2=0.23;x0=20;y0=10;seta=pi/20;
fliu(R,R2,x0,y0,seta,k)
R=0.6;R2=0.23;x0=19;y0=7;seta=pi/25;
fliu(R,R2,x0,y0,seta,k)
R=0.6;R2=0.23;x0=16;y0=5;seta=-pi/10;
fliu(R,R2,x0,y0,seta,k)
axis off
function fliu(R,R2,x0,y0,seta,k)
x=zeros(1,10);
y=x;
for i=1:5
x(2*(i-1)+1)=R*cos(pi/2+2*pi/5*(i-1)+seta);
x(2*i)=R2*cos(pi/2+2*pi/5*(i-1)+pi/5+seta);
y(2*(i-1)+1)=R*sin(pi/2+2*pi/5*(i-1)+seta);
y(2*i)=R2*sin(pi/2+2*pi/5*(i-1)+pi/5+seta);
end
x(11)=x(1);
y(11)=y(1);
x=x*k+x0;
y=y+y0;
fill(x,y,[1 0.7 0])
plot(x,y,"y")

=================================================

②2014,傳遞愛的正能量

=================我是源碼分割線=======================

[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")

=================================================

③不要想歪了哦^^,我是囧

=================我是源碼分割線=======================

syms x;
g=1/(x^2+2*x-3);
ezplot(g,-10,10);

=================================================

④帶上耳機,最炫民族風,high起來

=================我是源碼分割線=======================

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

fs = 44100; % sample rate
dt = 1/fs;
T16 = 0.125;
t16 = [0:dt:T16];
[temp k] = size(t16);
t4 = linspace(0,4*T16,4*k);
t8 = linspace(0,2*T16,2*k);
[temp i] = size(t4);
[temp j] = size(t8);
% Modification functions
mod4=(t4.^4).*exp(-30*(t4.^0.5));
mod4=mod4*(1/max(mod4));
mod8=(t8.^4).*exp(-50*(t8.^0.5));
mod8=mod8*(1/max(mod8));
mod16=(t16.^4).*exp(-90*(t16.^0.5));
mod16=mod16*(1/max(mod16));
f0 = 2*146.8; % reference frequency
ScaleTable = [2/3 3/4 5/6 15/16 ...
1 9/8 5/4 4/3 3/2 5/3 9/5 15/8 ...
2 9/4 5/2 8/3 3 10/3 15/4 4 ...
1/2 9/16 5/8];
% 1/4 notes
do0f = mod4.*cos(2*pi*ScaleTable(21)*f0*t4);
re0f = mod4.*cos(2*pi*ScaleTable(22)*f0*t4);
mi0f = mod4.*cos(2*pi*ScaleTable(23)*f0*t4);
fa0f = mod4.*cos(2*pi*ScaleTable(1)*f0*t4);
so0f = mod4.*cos(2*pi*ScaleTable(2)*f0*t4);
la0f = mod4.*cos(2*pi*ScaleTable(3)*f0*t4);
ti0f = mod4.*cos(2*pi*ScaleTable(4)*f0*t4);
do1f = mod4.*cos(2*pi*ScaleTable(5)*f0*t4);
re1f = mod4.*cos(2*pi*ScaleTable(6)*f0*t4);
mi1f = mod4.*cos(2*pi*ScaleTable(7)*f0*t4);
fa1f = mod4.*cos(2*pi*ScaleTable(8)*f0*t4);
so1f = mod4.*cos(2*pi*ScaleTable(9)*f0*t4);
la1f = mod4.*cos(2*pi*ScaleTable(10)*f0*t4);
tb1f = mod4.*cos(2*pi*ScaleTable(11)*f0*t4);
ti1f = mod4.*cos(2*pi*ScaleTable(12)*f0*t4);
do2f = mod4.*cos(2*pi*ScaleTable(13)*f0*t4);
re2f = mod4.*cos(2*pi*ScaleTable(14)*f0*t4);
mi2f = mod4.*cos(2*pi*ScaleTable(15)*f0*t4);
fa2f = mod4.*cos(2*pi*ScaleTable(16)*f0*t4);
so2f = mod4.*cos(2*pi*ScaleTable(17)*f0*t4);
la2f = mod4.*cos(2*pi*ScaleTable(18)*f0*t4);
ti2f = mod4.*cos(2*pi*ScaleTable(19)*f0*t4);
do3f = mod4.*cos(2*pi*ScaleTable(20)*f0*t4);
blkf = zeros(1,i);
% 1/8 notes
do0e = mod8.*cos(2*pi*ScaleTable(21)*f0*t8);
re0e = mod8.*cos(2*pi*ScaleTable(22)*f0*t8);
mi0e = mod8.*cos(2*pi*ScaleTable(23)*f0*t8);
fa0e = mod8.*cos(2*pi*ScaleTable(1)*f0*t8);
so0e = mod8.*cos(2*pi*ScaleTable(2)*f0*t8);
la0e = mod8.*cos(2*pi*ScaleTable(3)*f0*t8);
ti0e = mod8.*cos(2*pi*ScaleTable(4)*f0*t8);
do1e = mod8.*cos(2*pi*ScaleTable(5)*f0*t8);
re1e = mod8.*cos(2*pi*ScaleTable(6)*f0*t8);
mi1e = mod8.*cos(2*pi*ScaleTable(7)*f0*t8);
fa1e = mod8.*cos(2*pi*ScaleTable(8)*f0*t8);
so1e = mod8.*cos(2*pi*ScaleTable(9)*f0*t8);
la1e = mod8.*cos(2*pi*ScaleTable(10)*f0*t8);
tb1e = mod8.*cos(2*pi*ScaleTable(11)*f0*t8);
ti1e = mod8.*cos(2*pi*ScaleTable(12)*f0*t8);
do2e = mod8.*cos(2*pi*ScaleTable(13)*f0*t8);
re2e = mod8.*cos(2*pi*ScaleTable(14)*f0*t8);
mi2e = mod8.*cos(2*pi*ScaleTable(15)*f0*t8);
fa2e = mod8.*cos(2*pi*ScaleTable(16)*f0*t8);
so2e = mod8.*cos(2*pi*ScaleTable(17)*f0*t8);
la2e = mod8.*cos(2*pi*ScaleTable(18)*f0*t8);
ti2e = mod8.*cos(2*pi*ScaleTable(19)*f0*t8);
do3e = mod8.*cos(2*pi*ScaleTable(20)*f0*t8);
blke = zeros(1,j);
% 1/16 notes
do0s = mod16.*cos(2*pi*ScaleTable(21)*f0*t16);
re0s = mod16.*cos(2*pi*ScaleTable(22)*f0*t16);
mi0s = mod16.*cos(2*pi*ScaleTable(23)*f0*t16);
fa0s = mod16.*cos(2*pi*ScaleTable(1)*f0*t16);
so0s = mod16.*cos(2*pi*ScaleTable(2)*f0*t16);
la0s = mod16.*cos(2*pi*ScaleTable(3)*f0*t16);
ti0s = mod16.*cos(2*pi*ScaleTable(4)*f0*t16);
do1s = mod16.*cos(2*pi*ScaleTable(5)*f0*t16);
re1s = mod16.*cos(2*pi*ScaleTable(6)*f0*t16);
mi1s = mod16.*cos(2*pi*ScaleTable(7)*f0*t16);
fa1s = mod16.*cos(2*pi*ScaleTable(8)*f0*t16);
so1s = mod16.*cos(2*pi*ScaleTable(9)*f0*t16);
la1s = mod16.*cos(2*pi*ScaleTable(10)*f0*t16);
tb1s = mod16.*cos(2*pi*ScaleTable(11)*f0*t16);
ti1s = mod16.*cos(2*pi*ScaleTable(12)*f0*t16);
do2s = mod16.*cos(2*pi*ScaleTable(13)*f0*t16);
re2s = mod16.*cos(2*pi*ScaleTable(14)*f0*t16);
mi2s = mod16.*cos(2*pi*ScaleTable(15)*f0*t16);
fa2s = mod16.*cos(2*pi*ScaleTable(16)*f0*t16);
so2s = mod16.*cos(2*pi*ScaleTable(17)*f0*t16);
la2s = mod16.*cos(2*pi*ScaleTable(18)*f0*t16);
ti2s = mod16.*cos(2*pi*ScaleTable(19)*f0*t16);
do3s = mod16.*cos(2*pi*ScaleTable(20)*f0*t16);
blks = zeros(1,k);
% Melody by Schau_mal
part0 = [mi1f la0e la0e do1f mi1f ...
re1e re1s mi1s re1e do1e re1e do1e la0f ...
mi1f la0e la0e do1f mi1f ...
so1e re1s mi1s re1e do1e re1e do1e ti0e so0e ...
mi1f la0e la0e do1f mi1f ...
re1e re1s mi1s re1e do1e re1e do1e la0e so0e ...
mi1f la0e la0e do1f mi1f ...
so1e mi1e blkf blkf blkf ...
];
part1 = [la0f la0e so0e la0f la0e do1e ...
do1f re1e do1e la0f la0f ...
do1f do1e so0e do1e re1e mi1e so1e ...
so1e mi1e re1f mi1f mi1f ...
la1e la1e la1e so1e mi1e mi1f do1e ...
la0e la0e la0e mi1e re1s mi1s re1e re1f ...
mi1e mi1e so1e mi1e re1e mi1e re1e do1e ...
la0f so0f la0f la0f ...
];
part2 = [mi1e mi1e so1e mi1e mi1e so1e so1e la1e ...
do2e la1e so1f la1s do2s la1e la1f ...
la0f la0e so0e la0f do1f ...
re1e mi1s re1s do1e re1e mi1f mi1f ...
la0e la1e la1e so1e re1e mi1s re1s do1e re1e ...
mi1f mi1f blke blke blkf ...
do1e la0e la0e do1e re1f so0e so0e ...
mi1e so1e mi1e re1e do1f do1f ...
la0e do1e re1e mi1e re1e do1e so0e mi0e ...
la0f la0f blke blke blkf ...
];
part3 = [la0f la0e so0e la0f do1f ...
re1e mi1s re1s do1e re1e mi1f mi1f ...
la0e la1e la1e so1e re1e mi1s re1s do1e re1e ...
mi1f mi1f blke blke blkf ...
do1e la0e la0e do1e re1f so0e so0e ...
mi1e so1e mi1e re1e do1f do1e do1e ...
la0e do1e re1e mi1e so1e mi1e mi1e so1e ...
la1f la1f la1f la1f ...
];
part4 = [la1e la1s la1s la1e la1e la1e la1s so1s mi1e re1e ...
re1e re1s re1s mi1e mi1s so1s mi1e mi1s re1s do1e do1s la0s ...
la0f la0e so0e la0f la0e do1e ...
re1e mi1s re1s do1e re1e mi1f mi1f ...
la1e so1e mi1e re1e so1e mi1e re1e do1e ...
do1f do1f la0s do1s re1s mi1s re1s do1s la0s do1s
];
part5 = [do2e do2s do2s la1e la1s la1s so1e so1s so1s mi1e mi1s mi1s ...
re1e mi1s re1s do1e la0s so0s la0s so0s do1s re1s mi1s so1s la1s re2s ...
do2f do2f blks blks blks blks do1e re1e ...
mi1f mi1f mi1f so1e mi1e ...
la1f la1f la1e do1e so1e mi1e ...
re1f re1e re1s re1s re1e re1e do1e re1e ...
mi1f mi1e mi1s mi1s mi1e re1s do1s ti0e do1s re1s ...
mi1f mi1f mi1f so1e mi1e ...
do2f la1f la1f la1e do1e ...
re1f so1f so1f la1f ...
ti1f ti1f ti1f ti1f ...
];
part6 = [blkf blkf mi1e so1e mi1e so1e ...
mi1f la0e la0s la0s do1f la0e mi1s la0s ...
do1e do1s do1s re1e do1s re1s mi1f mi1f ...
mi1f la0e la0s la0s so1f re1e re1s re1s ...
mi1f mi1f mi1s re1s do1s la0s mi0s re0s mi0s so0s ...
do1f la0e la0s la0s re1f so0e so0s so0s ...
mi0f so0e so0s so0s do1f do1f ...
la0f do1e do1s la0s mi1e mi1s mi1s re1e re1s mi1s ...
];
% Combination, v1 is complete version, v2 is simple version.
v1 = [part0 part1 part1 part2 part3 part4 part0 part1 part1 part2 part3 part5 part3 part6 part3];
v2 = [part0 part1 part1 part2 part3 part5 part3 part6 part3];
% Let"s rock ^_^
s = v1;
s = s/max(s);
sound(s,fs);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

===============================================================

參考:

MATLAB中文論壇|Simulink中文論壇


你試試

&>&> why


被邀請回答問題了。但我還真不太清楚這種」有趣「的程序都有些什麼。

比如Matlab的那個Logo,可以用logo命令得到,其實是下面的語句優化而來:

&>&> surf(membrane(1))
&>&> shading interp


why

其實你打open why,會發現它的生成很簡單,隨機數+語法,你可以改成中文語法,增加和改動各類辭彙……


俄羅斯方塊

查stateflow的時候在demo裡面看到的,鏈接如下:Tetris - MATLAB amp; Simulink Example - MathWorks 中國

sf_tetris2

模型如下:

Stateflow Examples 還有很多有趣的模型,有興趣的可以看一看。

比如這個 Launch Abort System (Modeling a Launch Abort System)

sf_launchabort


不算是命令吧,一個腦洞很大的英國老師教的一個小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!
");

fprintf(1,"Message form start.m

");

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:
");

fprintf(1," rehash toolboxcache

");

cd ("~/Documents/MyMath/project");

------------------------------------------

然後!把你存放這個腳本的路徑加入Matlab搜索路徑里!home-set path-add with subfolder!後生切記!


spy


我也來答一個,今兒差點兒沒把我嚇死。

起因是跑圖像處理的程序,調用參數本來應該調用『image1』,錯寫成了『image』,運行過程中先出現了下面這幅圖

緊接著又報錯。

笑的怪瘮人的。。。。

我把這張圖發上朋友圈,收到的回復基本都是中毒了,迷之微笑。其中有一個朋友告訴我,這個孩子成年後成了一個連環殺手,已經被正法了。搞得我後背一陣發涼。。。

不過朋友圈裡還是有大神, @南慕倫 除了告訴我這件事情,還告訴我一些彩蛋。於是我發現了這個帖子,順便試了一遍這個問題下提到的各種小彩蛋,開啟了一片新世界。

嗯,最近越來越覺得自己寫東西的文筆差了。。。。

今天又學到一個新招,matlab奏卡農。轉自微博李月龍。是誰說的matlab除了不會生孩子,啥都行了。

但是。。。不唱玩停不下來。。。

% Cripple Pachebel"s Canon on Matlab

% Have fun

fs = 44100; % sample rate

dt = 1/fs;

T16 = 0.125;

t16 = [0:dt:T16];

[temp k] = size(t16);

t4 = linspace(0,4*T16,4*k);

t8 = linspace(0,2*T16,2*k);

[temp i] = size(t4);

[temp j] = size(t8);

% Modification functions

mod4 = sin(pi*t4/t4(end));

mod8 = sin(pi*t8/t8(end));

mod16 = sin(pi*t16/t16(end));

f0 = 2*146.8; % reference frequency

ScaleTable = [2/3 3/4 5/6 15/16 ...

1 9/8 5/4 4/3 3/2 5/3 9/5 15/8 ...

2 9/4 5/2 8/3 3 10/3 15/4 4 ...

1/2 9/16 5/8];

% 1/4 notes

do0f = mod4.*cos(2*pi*ScaleTable(21)*f0*t4);

re0f = mod4.*cos(2*pi*ScaleTable(22)*f0*t4);

mi0f = mod4.*cos(2*pi*ScaleTable(23)*f0*t4);

fa0f = mod4.*cos(2*pi*ScaleTable(1)*f0*t4);

so0f = mod4.*cos(2*pi*ScaleTable(2)*f0*t4);

la0f = mod4.*cos(2*pi*ScaleTable(3)*f0*t4);

ti0f = mod4.*cos(2*pi*ScaleTable(4)*f0*t4);

do1f = mod4.*cos(2*pi*ScaleTable(5)*f0*t4);

re1f = mod4.*cos(2*pi*ScaleTable(6)*f0*t4);

mi1f = mod4.*cos(2*pi*ScaleTable(7)*f0*t4);

fa1f = mod4.*cos(2*pi*ScaleTable(8)*f0*t4);

so1f = mod4.*cos(2*pi*ScaleTable(9)*f0*t4);

la1f = mod4.*cos(2*pi*ScaleTable(10)*f0*t4);

tb1f = mod4.*cos(2*pi*ScaleTable(11)*f0*t4);

ti1f = mod4.*cos(2*pi*ScaleTable(12)*f0*t4);

do2f = mod4.*cos(2*pi*ScaleTable(13)*f0*t4);

re2f = mod4.*cos(2*pi*ScaleTable(14)*f0*t4);

mi2f = mod4.*cos(2*pi*ScaleTable(15)*f0*t4);

fa2f = mod4.*cos(2*pi*ScaleTable(16)*f0*t4);

so2f = mod4.*cos(2*pi*ScaleTable(17)*f0*t4);

la2f = mod4.*cos(2*pi*ScaleTable(18)*f0*t4);

ti2f = mod4.*cos(2*pi*ScaleTable(19)*f0*t4);

do3f = mod4.*cos(2*pi*ScaleTable(20)*f0*t4);

blkf = zeros(1,i);

% 1/8 notes

fa0e = mod8.*cos(2*pi*ScaleTable(1)*f0*t8);

so0e = mod8.*cos(2*pi*ScaleTable(2)*f0*t8);

la0e = mod8.*cos(2*pi*ScaleTable(3)*f0*t8);

ti0e = mod8.*cos(2*pi*ScaleTable(4)*f0*t8);

do1e = mod8.*cos(2*pi*ScaleTable(5)*f0*t8);

re1e = mod8.*cos(2*pi*ScaleTable(6)*f0*t8);

mi1e = mod8.*cos(2*pi*ScaleTable(7)*f0*t8);

fa1e = mod8.*cos(2*pi*ScaleTable(8)*f0*t8);

so1e = mod8.*cos(2*pi*ScaleTable(9)*f0*t8);

la1e = mod8.*cos(2*pi*ScaleTable(10)*f0*t8);

tb1e = mod8.*cos(2*pi*ScaleTable(11)*f0*t8);

ti1e = mod8.*cos(2*pi*ScaleTable(12)*f0*t8);

do2e = mod8.*cos(2*pi*ScaleTable(13)*f0*t8);

re2e = mod8.*cos(2*pi*ScaleTable(14)*f0*t8);

mi2e = mod8.*cos(2*pi*ScaleTable(15)*f0*t8);

fa2e = mod8.*cos(2*pi*ScaleTable(16)*f0*t8);

so2e = mod8.*cos(2*pi*ScaleTable(17)*f0*t8);

la2e = mod8.*cos(2*pi*ScaleTable(18)*f0*t8);

ti2e = mod8.*cos(2*pi*ScaleTable(19)*f0*t8);

do3e = mod8.*cos(2*pi*ScaleTable(20)*f0*t8);

blke = zeros(1,j);

% 1/16 notes

fa0s = mod16.*cos(2*pi*ScaleTable(1)*f0*t16);

so0s = mod16.*cos(2*pi*ScaleTable(2)*f0*t16);

la0s = mod16.*cos(2*pi*ScaleTable(3)*f0*t16);

ti0s = mod16.*cos(2*pi*ScaleTable(4)*f0*t16);

do1s = mod16.*cos(2*pi*ScaleTable(5)*f0*t16);

re1s = mod16.*cos(2*pi*ScaleTable(6)*f0*t16);

mi1s = mod16.*cos(2*pi*ScaleTable(7)*f0*t16);

fa1s = mod16.*cos(2*pi*ScaleTable(8)*f0*t16);

so1s = mod16.*cos(2*pi*ScaleTable(9)*f0*t16);

la1s = mod16.*cos(2*pi*ScaleTable(10)*f0*t16);

tb1s = mod16.*cos(2*pi*ScaleTable(11)*f0*t16);

ti1s = mod16.*cos(2*pi*ScaleTable(12)*f0*t16);

do2s = mod16.*cos(2*pi*ScaleTable(13)*f0*t16);

re2s = mod16.*cos(2*pi*ScaleTable(14)*f0*t16);

mi2s = mod16.*cos(2*pi*ScaleTable(15)*f0*t16);

fa2s = mod16.*cos(2*pi*ScaleTable(16)*f0*t16);

so2s = mod16.*cos(2*pi*ScaleTable(17)*f0*t16);

la2s = mod16.*cos(2*pi*ScaleTable(18)*f0*t16);

ti2s = mod16.*cos(2*pi*ScaleTable(19)*f0*t16);

do3s = mod16.*cos(2*pi*ScaleTable(20)*f0*t16);

blks = zeros(1,k);

% Blank Block

blkblock = [blkf blkf blkf blkf blkf blkf blkf blkf...

blkf blkf blkf blkf blkf blkf blkf blkf];

% Base Melody

cello = [do1f do1f so0f so0f la0f la0f mi0f mi0f...

fa0f fa0f do0f do0f fa0f fa0f so0f so0f];

% So-FUCKING-Long Melody

violin = [mi2f mi2f re2f re2f do2f do2f ti1f ti1f...

la1f la1f so1f so1f la1f la1f ti1f ti1f ...%

do2f do2f ti1f ti1f la1f la1f so1f so1f...

fa1f fa1f mi1f mi1f fa1f fa1f re1f re1f ...%

do1f mi1f so1f fa1f mi1f do1f mi1f re1f...

do1f la0f do1f so1f fa1f la1f so1f fa1f...%

mi1f do1f re1f ti1f do2f mi2f so2f so1f...

la1f fa1f so1f mi1f do1f do2f blkf blke ti1e ...%

do2e ti1e do2e do1e ti0e so1e re1e mi1e...

do1e do2e ti1e la1e ti1e mi2e so2e la2e...

fa2e mi2e re2e fa2e mi2e re2e do2e ti1e...

la1e so1e fa1e mi1e re1e fa1e mi1e re1e... %%

do1e re1e mi1e fa1e so1e re1e so1e fa1e...

mi1e la1e so1e fa1e so1e fa1e mi1e re1e...

do1e la0e la1e ti1e do2e ti1e la1e so1e...

fa1e mi1e re1e la1e so1e la1e so1e fa1e...%

mi1f mi2e blke re2f re2f blkf do1f mi2f mi2f...

la2f la2f so2f so2f la2f la2f ti2f ti2f...%

do3e blke do2e blke ti1f ti1f blkf la1f do2f do2f...

do2f do2f do2f do2f do2f fa2f re2f so2f...%

so2e mi2s fa2s so2e mi2s fa2s so2s so1s la1s ti1s ...

do2s re2s mi2s fa2s mi2e do2s re2s...

mi2e mi1s fa1s so1s la1s so1s fa1s so1s mi1s fa1s so1s...

fa1e la1s so1s fa1e mi1s re1s mi1s re1s do1s re1s mi1s fa1s so1s la1s...

fa2e la1s so1s la1e ti1s do2s so1s la1s ti1s do2s re2s mi2s fa2s so2s...%

mi2e do2s re2s mi2e re2s do2s re2s ti1s do2s re2s mi2s re2s do2s ti1s...

do2e la1s ti1s do2e do1s re1s mi1s fa1s mi1s re1s mi1s do2s ti1s do2s...

la1e do2s ti1s la1e so1s fa1s so1s fa1s mi1s fa1s so1s la1s ti1s do2s...

la2e do2s ti1s do2e ti1s la1s ti1s do2s re2s do2s ti1s do1s la1s ti1s...%%

do2e blke blkf ti1e blke blkf la1e blke blkf do2e blke blkf...

do1e blke blkf do1e blke blkf do1e blke blkf do1e blke blkf...%

blkf so1e blke blkf so1e blke blkf mi1e blke blkf so1e blke...

blkf fa1e blke blkf mi1e blke blkf fa1e blke blkf re2e blke...%

mi2e mi1e fa1e mi1e re1e re2e mi2e re2e do2e mi1e do1e do2e ti1e so0e fa0e so0e...

la0e la1e so1e la1e so1e so0e fa0e so0e do1e la1e so1e la1e ti1e ti0e la0e ti0e...%

do1e do2e re2e do2e ti1e ti0e do1e ti0e la0e la1e so1e la1e ti1e ti0e mi1e re1e...

do1e do2e re2e fa2e mi2e mi1e so1e mi2e do2e fa2e mi2e fa2e re2e so1e fa1e so1e...%

mi1e so1e so1e so1e so1e so1e so1e so1e mi1e mi1e mi1e mi1e mi1e mi1e so1e so1e...

fa1e fa1e fa1e do2e do2e do2e do2e do2e do2e do2e la1e la1e so1e so1e re2e ti1e...%%

so1e mi2e mi2e mi2e re2e re2e re2e re2e do2e do2e do2e do2e so2e so2e so2e so2e...

la2e la2e la2e la2e so2e so2e so2e so2e la2e la2e la2e la2e ti2e ti1e ti1e ti1e...%

do2e do1s re1s mi1e do1e ti0e ti1s do2s re2e ti1e la1e la0s ti0s do1e la0e ti0e so1s fa1s mi1e re1e...

do1e mi1s re1s do1e fa1e mi1e do1s re1s mi1e so1e fa1e la1s so1s fa1e mi1e re1e so1s fa1s mi1e re1e...%

mi1e do2s ti1s do2e mi1e so1e so1s la1s ti1e so1e mi1e do2s re2s mi2e do2e mi2e mi2s re2s do2e ti1e...

la1e la1s so1s la1e ti1e do2e mi2s re2s do2e mi2e fa2e do2s ti1s la1e la1e so1e re1e so1e so1e...%

so1f so1f so1f so1f do1f do1f do1f so1f...

fa1f fa1f so1f so1f fa1f do1f do1f do1e ti0e...%

do1f do2f ti1f ti1f la1f la1f so1f so1f...

do1f do1e re1e mi1f mi1f do2f do2f ti1f ti1f...%%

do2f];

% cello

c1 = [cello cello cello cello cello...

cello cello cello cello cello...

cello cello cello cello cello...

cello cello cello cello cello...

cello cello cello blkf];

% violin1

v1 = [blkblock violin blkblock blkblock];

% violin2

v2 = [blkblock blkblock violin blkblock];

% violin3

v3 = [blkblock blkblock blkblock violin];

% Get dirty

s = c1+v1+v2+v3;

s = s/max(s);

sound(s,fs);


tic toc很實用不過可能沒什麼趣@_@

湊合當秒錶用吧


輸入 demo。你會得到更多更有趣的東西(?ω?)hiahiahia


function wav = matlabspeech(txt,voice,pace,fs)

% matlabspeech("I Love Maple and Matlab")

% matlabspeech("I Love Maple")

% matlabspeech("I Love Matlab")

if ~ispc, error("要求使用Microsoft Win32 SAPI ."); end

if ~ischar(txt), error("第一個參數是字元串."); end

SV = actxserver("SAPI.SpVoice");

TK = invoke(SV,"GetVoices");

if nargin &> 1

for k = 0:TK.Count-1

if strcmpi(voice,TK.Item(k).GetDescription)

SV.Voice = TK.Item(k);

break;

elseif strcmpi(voice,"list")

disp(TK.Item(k).GetDescription);

end

end

if nargin &> 2

if isempty(pace), pace = 0; end

if abs(pace) &> 10, pace = sign(pace)*10; end

SV.Rate = pace;

end

end

if nargin &< 4 || ~ismember(fs,[8000,11025,12000,16000,22050,24000,32000,...

44100,48000]), fs = 16000; end

if nargout &> 0

MS = actxserver("SAPI.SpMemoryStream");

MS.Format.Type = sprintf("SAFT%dkHz16BitMono",fix(fs/1000));

SV.AudioOutputStream = MS;

end

invoke(SV,"Speak",txt);

if nargout &> 0

wav = reshape(double(invoke(MS,"GetData")),2,[])";

wav = (wav(:,2)*256+wav(:,1))/32768;

wav(wav &>= 1) = wav(wav &>= 1)-2;

delete(MS);

clear MS;

end

delete(SV);

clear SV TK;

pause(0.2);

end

轉自啊嗷~找到好玩的了,MATLAB喊話小程序~~


推薦閱讀:

如何在 MATLAB 中實現車牌號圖片的識別?
matlab稀疏矩陣使用的是什麼數據結構?
如何用matlab畫天線的三維方向圖?
大家都用matlab做過哪些有趣的事兒?
如何對四旋翼飛行器進行精確的數學建模?

TAG:MATLAB |