日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 人工智能 > 循环神经网络 >内容正文

循环神经网络

matlab msgbox 换行,[转载]Matlab/GUI笔记

發(fā)布時(shí)間:2023/12/10 循环神经网络 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 matlab msgbox 换行,[转载]Matlab/GUI笔记 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

轉(zhuǎn)自 http://www.kylen314.com/archives/412

不顯示坐標(biāo)刻度:

set(gca,'xtick',[])

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

頻率響應(yīng):

[H,F]=freqz(b,1,512);

plot(F,20*log10(abs(H)));

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

濾波:

Y = Filter(A,B,X);

A/B慮X得到Y(jié)

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

播放音樂(lè):

sound(x,fs)

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

攝像頭模塊:

% 獲取攝像頭信息(imaqhwinfo)

imaqInfo = imaqhwinfo;

winvideoinfo = imaqhwinfo('winvideo');

n=length(winvideoinfo.DeviceInfo);% 看系統(tǒng)中有幾個(gè)攝像頭

% 調(diào)參數(shù),設(shè)置成使用最后一個(gè)攝像頭

CamNum=n;

device = winvideoinfo.DeviceInfo(CamNum)

% 分辨率設(shè)置,發(fā)現(xiàn)320x240時(shí)合適,640x480時(shí)只能預(yù)覽(若要處理則會(huì)表現(xiàn)出較大的延時(shí))

Format=device.SupportedFormats(3);% 'YUY2_320x240'

%Format=device.SupportedFormats(1);% 'YUY2_160x120'

% Format=device.SupportedFormats(end); % 'YUY2_640x480'

Format=char(Format);% 轉(zhuǎn)換成字符串

% 申請(qǐng)內(nèi)存空間

imaqmem(30000000);

VID = videoinput('winvideo',CamNum,Format);% 創(chuàng)建視頻輸入對(duì)象(videoinput)

preview(VID); % 顯示原始視頻

start(VID);

h=figure('NumberTitle','off','Name','處理后的視頻','MenuBar','none', 'Visible', 'on'); set(h,'doublebuffer','on');

while ishandle(h) % 判斷是否有效的圖像對(duì)象句柄

Iyuv=getsnapshot (VID); % 捕獲1幀圖像

I=ycbcr2rgb(Iyuv); % 將圖像從YUV空間轉(zhuǎn)換成RGB空間

flushdata(VID); % 清除數(shù)據(jù)獲取引擎的所有數(shù)據(jù)、置屬性SamplesAvailable為0

%TODO%

%%

drawnow; % 實(shí)時(shí)更新圖像,這句話很重要

end

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

計(jì)算運(yùn)行時(shí)間:

tic;

%%%%TODO%%%%

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

time_use = toc;

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

畫圖不同顏色連線:

h=plot(x(ii),y(ii),'o');

hold on;

col=rand(1,3);

set(h,'Color',col,'MarkerFaceColor',col);

xi1=x(i)*ones(size(ii));

xi2=y(i)*ones(size(ii));

line([x(ii)',xi1]',[y(ii)',xi2]','Color',col);

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

圖像中書寫文字:

text(.5,.5,['$',latex(x^2),'$'],'interpreter','latex','HorizontalAlignment','center','fontsize',18)

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

讀取wav文件:

[x, Fs, Bits]=wavread('readtest.wav');

if Bits==16

x=x*32768;

elseif?Bits==8

x=x*128;

end

播放wav文件:

music(x)

保存wav文件:

wavwrite(zz',44100,16,num2str(hm));

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

zplane:

num = input('Type in the numerator coefficients = ');

den = input('Type in the denominator coefficients = ');

K = num(1)/den(1);

Numfactors = factorize(num);%分解質(zhì)因數(shù)

Denfactors = factorize(den);

disp('Numerator factors');disp(Numfactors);

disp('Denominator factors');disp(Denfactors);

disp('Gain constant');disp(K);

zplane(num,den)

輸出:

Numerator factors

1.000000000000000 ??-2.100000000000001 ? ?5.000000000000003

1.000000000000000 ??-0.399999999999998 ? ?0.900000000000000

Denominator factors

1.000000000000000 ? ?2.000000000000000 ? ?4.999999999999996

1.000000000000000 ??-0.200000000000000 ? ?0.400000000000004

Gain constant

0.500000000000000

所以原始等于:

0.5*(1-2.1 z-1+5?z-2)(1-0.4 z-1+ 0.9 z-2)/(1+2 z-1+ 5?z-2)/(1 - 0.2 z-1+ 0.5 z-2)

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

轉(zhuǎn)灰度圖:

rgb2gray

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

批量重命名:

file = dir(['E:english gesture*.txt']);

for i = 1 : length(file)

str = ['rename ''E:english" "' file(i).name '.txt'' 'file(i).name(1) num2str(i+1) '.txt'];

system(str);

end

dir中文件路徑有空格可以直接寫,str中用有空格要用"?"來(lái)代替。

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

數(shù)據(jù)按指定格式寫到一個(gè)文本文件中去:

fid=fopen('e:/coe_8_v_rotate.arff','wt');%寫入文件路徑

fprintf(fid,'XXXXXnn');

fprintf(fid,'%g,',data);

fclose(fid);

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

1~n的隨機(jī)排列:

randperm(n)

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

計(jì)算眾數(shù):

mode

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

隨機(jī)整數(shù):

out = randint(1,1,[0,100])

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

組合數(shù):

nchoosek(5,2)

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

組合結(jié)果:

combntns([1 2 3 4],2)

ans = 1 2 1 3 1 4 2 3 2 4 3 4

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

誤差累積函數(shù)和反運(yùn)算:

normcdf

norminv

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

符合正態(tài)隨機(jī)分布的隨機(jī)數(shù):

R = normrnd(MU,SIGMA)

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

繪制雙縱坐標(biāo)系曲線:

plotyy(X1,Y1,X2,Y2)

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

采樣:

downsample(a,R)

decimate可以設(shè)置濾波器,細(xì)節(jié)不好控制

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

畫時(shí)頻圖:

spectrogram (S, 窗大小, 窗重疊部分大小, 福利葉變換長(zhǎng)度,采樣率) )

或者:

[y,f,t,p] = spectrogram (data, N_w, N_overlap, N_fft, Fs_d,'yaxis');

surf(t,f,10*log10(abs(p)),'EdgeColor','none');

axis xy; axis tight; colormap(jet); view(0,90);

xlabel('Time');

ylabel('Frequency (Hz)');

colorbar;

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

figure設(shè)置全屏:

set(gcf,'outerposition',get(0,'screensize'));

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

按特定格式讀取文件的數(shù)據(jù):

[a b c d...] = textread(file_name,format);

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

按行讀取文件的數(shù)據(jù):

fidin=fopen('test.txt');

while ~feof(fidin)

line_read=fgetl(fidin);

end

close(fidin);

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

設(shè)置畫圖data cursor的顯示模式:

重寫函數(shù)myupdatefcn

function doc_datacursormode()

fig = figure;

a = -16; t = 0:60;

plot(t,sin(a*t))

dcm_obj = datacursormode(fig);

set(dcm_obj,'UpdateFcn',@myupdatefcn)

% Click on line to select data point

function txt = myupdatefcn(empt,event_obj)

pos = get(event_obj,'Position');

txt = {['Time: ',num2str(pos(1))],...

['Amplitude: ',num2str(pos(2))]};

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

指定小數(shù)位數(shù)格式化字符串:

str=sprintf('x=%.3f,y=%.3f',x,y);

disp(str);

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

plot中添加描述文字:

text(x,y,str,'FontSize',18);

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

數(shù)據(jù)擬合工具:

打開cftool

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

圖像處理操作:

I=rgb2gray(RGB);%灰度化

imhist(I); %畫出直方圖對(duì)比

newA = histeq(rgb2gray(A));%%直方圖均衡化

newA = imresize(newA,[sizeM,sizeN]);

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

排版整理快捷鍵:

ctrl+i

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

發(fā)郵件接口(可以用于程序跑完給自己發(fā)一封郵件):

function send_E_mail(from_address, password, to_address, subject, message)

setpref('Internet', 'E_mail', from_address);

setpref('Internet', 'SMTP_Username', from_address);

setpref('Internet', 'SMTP_Password', password);

props = java.lang.System.getProperties;

props.setProperty('mail.smtp.auth','true');

props.setProperty('mail.smtp.socketFactory.class','javax.net.ssl.SSLSocketFactory');

props.setProperty('mail.smtp.socketFactory.port','465');

sendmail(to_address, subject, message);

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

matlab說(shuō)話:

sp=actxserver('SAPI.SpVoice');

sp.Speak('你是豬')

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

函數(shù)繪圖:

1)ezplot('sin(x)')

系列函數(shù):ezcontour,ezcontourf,ezmesh,ezmeshc,ezplot3,ezpolar,ezsurf,ezsurfc

2)fplot('sin(x)',[0 2*pi])

3)function y=my_fun(x)

y = sin(x);

調(diào)用時(shí):fplot('my_fun',[0 2*pi])

4)匿名函數(shù):

f=@(x)sin(x);%定義x為輸入?yún)?shù)

fplot(f,[0 2*pi])

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

雙y軸畫圖:

plotyy()

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

y軸取對(duì)數(shù)畫圖:

semilogy ()

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

在鼠標(biāo)點(diǎn)擊的位置顯示字符串:

gtext

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

TEX字符:

it斜體,AE設(shè)為斜體'{itAE}'

rm正常

text(0,0,'$frac{1}{2}$','interpreter','latex')

text('string','$frac{1}{2}$','interpreter','latex','fontsize',40,'pos',[4 1])

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

字符作圖:

text(x,y,'D')

當(dāng)xy為矩陣的時(shí)候,相當(dāng)于用字符'D'來(lái)畫圖

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

修改text:

text_handle=text(.2,.1,'修改前字符串');

pause(10);

set(text_handle,'string',‘修改后字符串’);

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

帶背景顏色text:

text(6,1.2,'downarrow aa','BackgroundColor','b', 'FontWeight','bold','Color','y');

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

text多行顯示:

多行用元胞{'第一行','第二行'}

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

x軸為時(shí)間:

datetick

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

各種統(tǒng)計(jì)圖畫法:

面積圖:area

柱狀圖分組畫法,bar,輸入矩陣每行為一組,bar(x,'group')

柱狀圖每組疊加成一列:bar(x,'stack')

柱狀圖橫著畫:barh

階梯圖:stairs

角度直方圖rose

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

元胞設(shè)置作圖多個(gè)屬性(加上v6)

PN_array={'Color','LineWidth','Marker'};

PV_array={'y',3,'d'};

plot(‘v6’,cos(x),sin(x),PN_array,PV_array)

或者

PS_array.Color='m';PS_array.LineWidth=2;

line(cos(5*x),sin(5*x),PS_array);

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

繪圖后不顯示菜單欄:

set(gcf,'menubar','none');

恢復(fù)

set(gcf,'Menubar','figure');

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

繪圖后背景顏色:

set(gcf,'Color','w');

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

繪圖窗口大小設(shè)置:屏幕左下角為(0,0)

set(gcf,'position',[50 50 200 200])

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

坐標(biāo)軸等長(zhǎng):

axis square

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

作圖的marker設(shè)置:

plot(x,y,'r--s','LineWidth',2,'MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',5);

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

多個(gè)繪圖中設(shè)置其中一條的屬性:

p=plot(t,y1,t,y2,t,y3,);

set(p(1),'LineWidth',2);

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

cla:清除坐標(biāo)軸以外的

clf:清除全部

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

雙y軸繪圖修改不同y軸屬性:

[AX,H1,H2] = plotyy(x,y1,x,y2,'plot');

set(get(AX(1),'Ylabel'),'String','Left Y-axis')

set(get(AX(2),'Ylabel'),'String','Right Y-axis')

set(H1,'LineStyle','--')

set(H2,'LineStyle',':')

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

設(shè)置坐標(biāo)刻度記號(hào):

set(gca,'XTick',-pi:pi/2:pi);

set(gca,'XTickLabel',{'-pi','-pi/2','0','pi/2','pi'});

set(gca,'fontname','symbol');%用π來(lái)代替pi

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

格式化字符串:

sprintf('a=%.4f',1/9)

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

最小刻度網(wǎng)格線:

set(gca,'xminorgrid','on')

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

誤差圖:

x=linspace(0,2*pi);

y=sin(x);

e = std(y)*ones(size(x));

errorbar(x,y,e,'d');

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

極坐標(biāo)轉(zhuǎn)笛卡爾坐標(biāo)系:

[u,v] = pol2cart(theta,r);

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

羽毛圖:(比如用于表示頻譜的相位信息)

feather(U,V)

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

箭頭圖:(極坐標(biāo)下表示矢量)

compass(x,y)

注:標(biāo)注text的時(shí)候,原點(diǎn)在極坐標(biāo)原點(diǎn)

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

顏色映射雜七雜八:

1)colormap參數(shù)可以是hot, hsv, summer, autumn,

bone, colorcube, cool, copper, flag, gray, hot, hsv, jet, pink, lines,

prism, spring, white, winter 等等

2)自定義映射圖:colormap(K)

K是N×3

3)colormapeditor來(lái)編輯

4)修改colorbar:

h_CBar = colorbar;

PS=get(h_CBar, 'Position');

get(h_CBar,'ylim')

set(h_CBar,'ytick',[-6 1 8]);

set(h_CBar,'yticklabel',{'上','中','下'});

5)insert-》colorbar

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

餅狀圖突出某個(gè)值:

x=[20 10 15 25 30];

explode=[0 1 0 0 0];

data={'a','b','c','d','e'};

%獲取某部分餅的句柄方式

set(h(4),'FontWeight','bold','FontSize',18,'EdgeColor','red');

h=pie(x,explode, data);

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

薄片彩帶圖:

ribbon(x,y)

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

填充多邊形:

fill(x,y,'r')

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

計(jì)算多邊形的面積:

ployarea(x,y)

注:不可有交點(diǎn)

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

分散矩陣:

plotmatrix(x,y)

X是P×M,Y是P×N,結(jié)果則是N×M

如果plotmatrix(y,y)或plotmatrix(y),對(duì)角線為柱狀圖

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

subplot獲取各個(gè)子圖句柄:

get(gcf,'Children')

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

坐標(biāo)軸刻度朝外:

set(gca,'tickdir','out');

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

坐標(biāo)軸刻度長(zhǎng)度:

set(gca,'ticklength',[0.03 0.025]);

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

指定位置畫子圖:(左下角為坐標(biāo)原點(diǎn))

subplot('position',[0.2,0.05,0.6,0.45]);

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

鼠標(biāo)點(diǎn)擊獲取數(shù)據(jù):

[x y Iseffect]=ginput(點(diǎn)數(shù))

Iseffect返回點(diǎn)擊是否有效

不輸入點(diǎn)數(shù)則按回車后才結(jié)束

或者用[x y]=getpts(fig)

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

圖片中用data cursor選取多個(gè)數(shù)據(jù):

alt+點(diǎn)擊左鍵

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

隱藏坐標(biāo)軸:

set(gca,'visible','off')

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

三維繪圖旋轉(zhuǎn)開啟:

rotate3d on

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

等高線:

contour(z)

contour(z,條數(shù))

contour(z,指定高度)

注:z至少2×2以上

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

繪制偽彩色圖:

pcolor(z)

shading interp;%用于偽彩色圖或者surf之類的插值

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

等高線數(shù)值標(biāo)注:

=contour(peaks);

clabel(c,h);

colorbar;

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

產(chǎn)生球體:

[X,Y,Z] = sphere;

Origin = rand(1,3);

surf(X*R+Origin(1),Y*R+Origin(2),Z*R+Origin(3));

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

向量圖:(比如用于描述磁場(chǎng)之類的)

quiver(U,V)

quiver(X,Y,U,V)

示例:

[X,Y] = meshgrid(-2:.2:2);

Z = X.*exp(-X.^2 - Y.^2);

[DX,DY] = gradient(Z,.2,.2);

contour(X,Y,Z)

hold on

quiver(X,Y,DX,DY)

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

三維畫表面圖:

mesh:網(wǎng)格

surf:表面

meshc,surfc:配上等高線

surfl:光源效果

光源位置:light('position',[-3,-1,3],'style','local')

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

mesh,surf挖空方法:

[X,Y,Z]=peaks(25);

index=find(X<0&Y<0);

Z(index)=NaN;

surf(X,Y,Z);

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

瀑布圖:(沿著某個(gè)方向?yàn)榫€條形式的圖)

[x y z]=peaks(30);

waterfall(x,y,z)

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

三維網(wǎng)格圖透明設(shè)置:

hidden

也可以help alpha

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

rgbplot(x)

畫紅綠藍(lán)三條曲線,x必須是M×3的矩陣。

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

旋轉(zhuǎn)顏色映射產(chǎn)生動(dòng)畫效果:

spinmap

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

播放電影方式播放動(dòng)畫:(內(nèi)存消耗嚴(yán)重)

for i=1:N plot_command m(:,i)=getframe;endmovie(m)

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

更新y值方式播放動(dòng)畫:

t=0:0.05:10*pi;h=plot(t,sin(2*t).*exp(-t/5),'EraseMode','xor');for i=1:200? y=sin(2*t+i/10).*exp(-t/5); set(h,'ydata',y); drawnow; end

如果EraseMode為none,則全部軌跡保留(別的選項(xiàng)還有normal,background)

記得要開雙緩沖set(gcf,'DoubleBuffer','on'),原理應(yīng)該是和MFC一樣

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

動(dòng)畫保存為avi:

aviobj = avifile('animation.avi','fps',3); for k=1:25 h = plot(fft(eye(k+16))); set(h,'EraseMode','xor'); axis equal; frame = getframe(gca); aviobj = addframe(aviobj,frame);endaviobj = close(aviobj);

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

獲取子窗口位置:

get(h1,'Position');

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

獲取子窗口邊界:

get(h1,'TightInset');

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

構(gòu)造矩形框?qū)嵗?#xff1a;

annotation('rectangle',[x1,y1,w,h],'FaceAlpha',.2,'FaceColor','red','EdgeColor','red');

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

構(gòu)造雙箭頭:

annotation('doublearrow',[0 0.5],[0 0.3])

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

獲取屬性值:

get(h, 'MarkerSize')

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

獲取父對(duì)象:

ph=get(m, 'Parent') ;

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

獲取對(duì)象的所有屬性值:

get(h)

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

刪除句柄對(duì)象:

delete(h)

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

查看一個(gè)屬性的所有可能值:

set(h,'屬性')

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

查找對(duì)象句柄:

b_handles=findobj(gca,'Color','b');

h = findobj(gca,'type','line')

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

找到句柄后打開編輯界面:

inspect(b_handles)

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

元胞轉(zhuǎn)矩陣:

cell2mat

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

figure全屏:

set(gcf,'outerposition',get(0,'screensize'));

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

鼠標(biāo)點(diǎn)擊函數(shù):

d=plot(rand(5));

set(d,'ButtonDownFcn','set(gcbo,''Color'',''r'',''linew'',5)') ;

%gcbo為鼠標(biāo)點(diǎn)擊返回值

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

關(guān)閉figure時(shí)執(zhí)行的函數(shù):

fig=plot(rand(10));

set(fig1,'closerequestfcn','my_closereq')

然后編寫my_closereq:

selection = questdlg('Close Specified Figure?', 'Close Request Function',...

'Yes','No','Yes');

switch selection

case 'Yes'

delete(gcf)

case 'No'

return

end

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

自己繪制figure界面光標(biāo)示例:

P = ones(16)+1;

P(1,:) = 1; P(16,:) = 1;

P(:,1) = 1; P(:,16) = 1;

P(1:4,8:9) = 1; P(13:16,8:9) = 1;

P(8:9,1:4) = 1; P(8:9,13:16) = 1;

P(5:12,5:12) = NaN;

set(gcf,'Pointer','custom','PointerShapeCData',P,...

'PointerShapeHotSpot',[9 9])

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

畫圖論那種圖

gplot(A,Coordinates)畫圖的頂點(diǎn),其中Coordinates是代表頂點(diǎn)的坐標(biāo),Coordinates是n*2矩陣,A是n*n的鄰接矩陣,n是頂點(diǎn)的個(gè)數(shù)。

示例:k = 1:30;

[B,XY] = bucky;

gplot(B(k,k),XY(k,:),'-*')

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

構(gòu)造坐標(biāo)軸:

axes_handles(1)=axes('position',[0.1 0.05 0.2 0.2]);

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

字符串轉(zhuǎn)元胞:

cellstr

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

字符創(chuàng)所代表的matlab的值:

eval('linspace(0,2,100)')

如果GUI生成可執(zhí)行文件時(shí),則必須用feval

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

查找工作空間中的變量:

evalin('base','who')

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

工作空間變量賦值:

assignin('base','name',Value)

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

批量創(chuàng)建和計(jì)算變量:

for n = 1:12

eval(['M' num2str(n) ' = magic(n)'])

end

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

字符串計(jì)算實(shí)例:

surf(x,y,eval(string))

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

同次項(xiàng)合并:

collect

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

字符串轉(zhuǎn)表達(dá)式:

sym(string)

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

獲取時(shí)間字符串:

datestr(now)

current_t = datestr(clock,'mmm.dd,yyyy HH:MM:SS')

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

打開保存文件對(duì)話框:

[FileName,PathName] = uiputfile('*.jpg','Save File');

file = strcat(PathName,FileName);

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

打開open對(duì)話款:

file = uigetfile('*.fig');

if ~isequal(file,0)

open(file);

end

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

整合方式構(gòu)造結(jié)構(gòu)體:

c = {'tree',37.4,'birch'};

f = {'category','height','name'};

s = cell2struct(c,f,2);

>> s.category

ans =

tree

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

正則表達(dá)式:

regexp(str,pattern,mode)

pattern通配符用.*?

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

生成制作動(dòng)畫:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

figure

axis equal

axis([-1 1 -1 1]*1.1)

set(gca, 'XTick', -1:0.5:1, 'YTick', -1:0.5:1)

grid on

set(gca, 'NextPlot', 'replaceChildren')

n = 100;

t = linspace(0, 2*pi, n);

M = moviein(n);

fori = 1 : n

x = cos(t(1:i));

y = sin(t(1:i));

plot(x, y)

M(i) = getframe;

end

movie(M)

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

制作gif:

1

2

3

4

5

6

7

8

9

10

11

12

13

fori = 1 : 250

plot(...)

f=getframe(gcf);

imind=frame2im(f);

[imind,cm] = rgb2ind(imind,256);

%第一次必須創(chuàng)建!

ifi==1

imwrite(imind,cm,file_name,'gif', 'Loopcount',inf,'DelayTime',0.01);

else

imwrite(imind,cm,file_name,'gif','WriteMode','append','DelayTime',0.01);

end

end

此分界線下面為GUI部分:

uicontrol:Style:

[ {pushbutton} | togglebutton | radiobutton | checkbox | edit | text | slider | frame | listbox | popupmenu ]

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

popup控件:

設(shè)置選項(xiàng):

'string','a|b|c'

獲取選項(xiàng):

get(h,Value),返回值:1,2,3...

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

uimenu:

f=uimenu(gcf,'Label', 'XXX','Callback', 'XXXX');

子菜單:

f1=uimenu(f,.....);

position=1,2,3可以指定位置

快捷鍵:

label中加&(結(jié)果為alt+按鍵)

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

鼠標(biāo)右鍵出現(xiàn)的菜單:

uicontextmenu,用法同menu

rwm=uicontextmenu;

uimenu(rwm,'Label','XXX'...)

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

豎著的slider:

修改寬高比

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

復(fù)選框:

set(handles.XX,'checked','on')%or 'off'

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

Import菜單功能:

callback中填寫uiimport

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

print菜單功能:

callback中填寫printdlg

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

退出的菜單功能:

selection = questdlg(['是否關(guān)閉',get(gcf,'Name'),'窗口'], ...

['Close ',get(gcf,'Name'),'...'], ...

'是','否','是');

if strcmp(selection,'否')

return;

else

delete(gcf);

end

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

help菜單:

寫一個(gè)html文件,然后:

wed(['file:' which('XXX.html')])

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

ToggleButton/CheckBox:

if get(gcbo,'Value')==1;

%TODO

else

%TODO

end

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

ListBox:

獲取字符串:

get(h,'string')

獲取選中的索引:

get(h,'value')

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

RadioButton批量設(shè)置值為0:

將各個(gè)句柄值設(shè)置為:Radio_h(1),Radio_h(2)...

if get(gcbo,'Value')==1

set(Radio_h(Radio_h ~= gcbo), 'value',0)

end

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

EditText多行輸入:

Max設(shè)置為2(保證Max-min>1)

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

ListBox多選:

Max設(shè)置為2(保證Max-min>1)

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

GUI生成exe

mcc -m xxxx

執(zhí)行exe文件:!xxxx

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

統(tǒng)一管理GUI CallBack函數(shù):

function gui_fcn(action)

switch action

case 'Close'

case 'Peaks'

case 'Export'

otherwise

end

callback中填寫類似:gui_fcn Close

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

鼠標(biāo)移動(dòng)到控件上的提示字符串:

tooltipstring

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

添加圖片:

himge = findobj('tag','pic1');

axes(himge);

logo = imread('1.jpg');

image(logo);

set(himge,'visible','off')

set(himge,'handlevisibility','off')

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

圖標(biāo)顯示在按鈕上:

A = imread('2.jpg');

bu = findobj('tag','logobutton');

set(bu,'cdata',A);

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

對(duì)于figure,等待按鍵:

fig_h=figure(1);

waitforbuttonpress;%(阻塞)

if get(fig_h,'CurrentCharacter')==13

%todo

end

按鍵:tab(9),回車(13),ESC(17),上下左右(28-31),空格(32)

code = double(get(fig_h,'CurrentCharacter'))

對(duì)于waitforbuttonpress,返回0表示有鼠標(biāo)點(diǎn)擊,返回1表示鍵盤按鍵

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

獲取按鍵

function figure1_KeyPressFcn(hObject, eventdata, handles)

key = get(hObject,'CurrentCharacter');

如果不在KeyPressFcn中,則是無(wú)時(shí)無(wú)刻都在等待獲取,比如

while double(get(F,'CurrentCharacter'))~=27

set(edit1,'String',datestr(now));

pause(.1);

end

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

currentkey:

返回值與CurrentCharacter不同,比如上下左右返回是uparrow,downarrow等,F1返回是f1,小鍵盤數(shù)字鍵1返回是numpad1等。

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

selectiontype:

還可以返回alt,shift等按鍵信息

返回extent表示shift+左鍵或同時(shí)按下左右鍵

返回normal表示左鍵

返回alt表示alt或者右鍵

返回open表示雙擊左鍵或者右鍵

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

currentpoint:

返回鼠標(biāo)最后單擊或者釋放的位置

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

進(jìn)度條:

h = waitbar(0,'進(jìn)行中');

for i = 1 :10000

waitbar(i/10000,h);

end

close(h)

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

群組按鈕實(shí)例:(可用于制作工具欄)

fig=figure('Position',[200 200 250 120],'Name','btngroup 絛ㄒ',...

'NumberTitle','off','Menubar','none');

icons = ['text(.5,.5,''B1'',''HorizontalAlignment'',''center'')'

'text(.5,.5,''B2'',''HorizontalAlignment'',''center'')'];

callbacks = ['disp(''B1'')';'disp(''B2'')'];

btngroup(fig,'GroupID', 'TestGroup', 'ButtonID', ['B1';'B2'], 'Callbacks', callbacks, ...

'Position', [.4 .45 .25 .3], 'IconFunctions', icons);

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

按下左鍵開始才開始定義消息函數(shù):

建立m文件:

function mouse(action)

switch action

case 'start'

set(gcbf,'windowbuttonmotionfcn','mouse move');

set(gcbf,'windowbuttonupfcn','mouse stop');

case 'move'

point = get(gca,'CurrentPoint');

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

case 'stop'

set(gcbf,'windowbuttonmotionfcn','');

set(gcbf,'windowbuttonupfcn','');

end

在axis的 buttondownfcn中寫:mouse start

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

設(shè)置F1的函數(shù):

set(gcf,'HelpFcn','XXXXXX');

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

listbox顯示當(dāng)前目錄下的所有文件列表,點(diǎn)擊并加載文件

list_h=uicontrol('style', 'listbox','Position',[25 10 200 250]);

d=dir;

set(list_h,'string',{d.name},'Callback',...

['Value = get(gcbo,''Value'');',...

'String = get(gcbo,''String'');',...

'String = cellstr(String);',...

'uiimport(String{Value})']);

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

二維列表:

f = figure;

data = rand(3);

colnames = {'X-Data', 'Y-Data', 'Z-Data'};

t = uitable(f, 'Data', data, 'ColumnName', colnames, ...

'Position', [20 20 260 100]);

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

陣列方式來(lái)排控件示例:

figure('name', 'uiarray', 'numbertitle', 'off');

figPos = get(gcf, 'pos');

bigFramePos = [0 0 figPos(3) figPos(4)];

m = 4; n = 3;

border = 20; spacing = 10;

style = str2mat('push', 'slider', 'radio', 'popup', 'check');

callback = 'disp([''This is a '' get(gco, ''style'')])';

string = str2mat('one', 'two', 'three', 'four-1|four-2|four-3', 'five');

uiarray(bigFramePos, m, n, border, spacing, style, callback, string);

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

文件夾樹控件:

uitree('root','d:');

uitree('root',0)可以構(gòu)造關(guān)于控件關(guān)系的樹

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

超簡(jiǎn)易選擇對(duì)話框:

select = menu('提示信息','選項(xiàng)1','選項(xiàng)2');

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

提示對(duì)話框:(換行用n)

msgbox('信息標(biāo)題','對(duì)話框標(biāo)題','help')

msgbox('信息標(biāo)題','對(duì)話框標(biāo)題','warn')

msgbox('信息標(biāo)題','對(duì)話框標(biāo)題','error')

msgbox('信息標(biāo)題','對(duì)話框標(biāo)題','custom')%自己設(shè)計(jì)圖標(biāo)

示例:

Data=1:256;Icon=(Data'*Data)/128;

msgbox('信息標(biāo)題','對(duì)話框標(biāo)題','custom',Icon,copper(128))

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

模態(tài)對(duì)話框方式:

h = msgbox('信息標(biāo)題','對(duì)話框標(biāo)題');

waitfor(h);

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

設(shè)置對(duì)話框背景顏色:

set(h,'color','w');

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

修改提示對(duì)話框字體:

通過(guò)findall語(yǔ)句來(lái)實(shí)現(xiàn):

hm=msgbox('信息標(biāo)題','對(duì)話框標(biāo)題','error');

set(hm,'color','w');

th=findall(hm,'Type','Text');

set(th,'color','r');

set(th,'FontSize',24);

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

問(wèn)題選擇對(duì)話框:(返回的是字符串)

Button=questdlg('請(qǐng)選擇','標(biāo)題','選項(xiàng)0', '默認(rèn)選項(xiàng)','選項(xiàng)2','默認(rèn)選項(xiàng)');

最多3個(gè)選項(xiàng)

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

輸入對(duì)話框:

answer=inputdlg(提示語(yǔ),dlgTitle,對(duì)話框間距,默認(rèn)值);

多個(gè)需要輸入的選項(xiàng)提示語(yǔ)可以用{'問(wèn)題1','問(wèn)題2'},返回值答案用answer{i}

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

輸入對(duì)話框編輯cancel選項(xiàng):

if isempty(answer)

XXXXXXXXX

end

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

列表選擇對(duì)話框:

str = {'A', 'B', 'C', 'D', 'E'};

[s,ok] = listdlg('PromptString','請(qǐng)選擇','name','title','SelectionMode','single',...

'ListString',str, 'fus',10, 'ListSize',[160 80]);

ok為1表示有選,0表示沒(méi)有選擇

s是索引

其中okstring,cancelstring設(shè)置按鈕的文字

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

設(shè)置顏色對(duì)話框:

text_handle=uicontrol('Style','text','Position',[250 250 120 20],...

'String','被設(shè)置的text');

uisetcolor(text_handle,'標(biāo)題');

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

設(shè)置字體對(duì)話框:

figure;

hText=gtext('12345');

uisetfont(hText, 'Update Font');

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

添加工具欄圖標(biāo):

uipushtool('Separator','on','TooltipString','提示信息',...

'ClickedCallback','msgbox(''XXX'',''XXXX'')','CData',repmat(magic(12)/12^2,[1 1 3]));

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

偏好設(shè)置對(duì)話框:

uigetpref

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

設(shè)置定時(shí)器:

t = timer('Period',1.0,'ExecutionMode','fixedrate','StartDelay',0.5,'timerfcn','XXXX');

start(t);

timerfcn調(diào)用方法:{‘functionname’,par1,par2...}

functionname的定義是:function functionname(t,event,para1,para2...)

timer中tasksexecuted表示重復(fù)執(zhí)行的次數(shù)

總結(jié)

以上是生活随笔為你收集整理的matlab msgbox 换行,[转载]Matlab/GUI笔记的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。