Thứ Bảy, 2 tháng 7, 2011

Làm quen Matlab

- Hàm lấy và gán giá trị:
get(handles.tagName, 'String');
set(handles.tagName, 'String', value);
guidata(hObject, handles);

- Các hàm biến đổi:
str2num(value)
num2str(value)

- Create and open message box: msgbox
h = msgbox(Message)
h = msgbox(Message,Title)
h = msgbox(Message,Title,Icon)
h = msgbox(Message,Title,'custom',IconData,IconCMap)
h = msgbox(...,CreateMode)

- Xuống dòng trong msgbox:
msg = {}
msg{1} = 'line 1';
msg{2} = 'line 2';
msgbox(msg, 'Vi du');

- Open standard dialog box for retrieving files: uigetfile
filename = uigetfile
[FileName,PathName,FilterIndex] = uigetfile(FilterSpec)
[FileName,PathName,FilterIndex] = uigetfile(FilterSpec,DialogTitle)
[FileName,PathName,FilterIndex] = uigetfile(FilterSpec,DialogTitle,DefaultName)
[FileName,PathName,FilterIndex] = uigetfile(...,'MultiSelect',selectmode)

VD:
[filename, pathname] = ...
uigetfile({'*.mp3';'*.wav'},'Chon file am thanh','D:\Downloads\Music','MultiSelect','on');

if isequal(size(filename),0)
disp('User selected Cancel');
else
count = length(filename);
for i=1:count
disp(fullfile(pathname, filename{i}));
end
end


- Làm việc với file:
+ uiputfile
+ uigetfile
+ fopen
+ fgets
+ fprintf
+ Open file, or obtain information about open files: fopen
fileID = fopen(filename)
fileID = fopen(filename, permission)
permission:
'r' Open file for reading (default).
'w' Open or create new file for writing. Discard existing contents, if any.
'a' Open or create new file for writing. Append data to the end of the file.
'r+' Open file for reading and writing.
'w+' Open or create new file for reading and writing. Discard existing contents, if any.
'a+' Open or create new file for reading and writing. Append data to the end of the file.
'A' Append without automatic flushing. (Used with tape drives.)
'W' Write without automatic flushing. (Used with tape drives.)

- Play file wav:
[y, Fs, nbits, readinfo] = wavread('C:\File01.wav');
p = audioplayer(y, Fs);
play(p);

- Mảng:
arr = {}
arr{1} = 'aaa';
arr{2} = 'bbb';


Tham khảo:
http://blinkdagger.com/matlab/matlab-gui-graphical-user-interface-tutorial-for-beginners/

2 nhận xét: