An introduction to MATLAB

506 views

Published on

a general presentation with MATLAB program and some usefu tricks.

Published in: Education, Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
506
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

An introduction to MATLAB

  1. 1. 使用 Matlab GUI 建立簡單的加法 器和創建卡的魔術。
  2. 2. 大網 前言 加法器 卡的魔術 結論
  3. 3. MATLAB (矩陣實驗室)是一個數值計算環境和第四代編程語言。 第一 Matlab 軟件已經制定於1984 年。在工程世界, MATLAB 是一個非常重要的軟體,因為它可以:•建立軟體•創建應用程序•解決數學函數我們將建立一個簡單的加法器和創建一個卡的魔術。
  4. 4. 一 . 加法器步驟1.打開 MATLAB command: >> guide blank GUI2.拖放 :3.2 ‘edit text’ 按鈕 = inputs 輸入equal sign 等號 (=)1.2 ‘static text’ 按鈕2. output 產量3.1 ‘push button’ 按鈕 = sign 加號
  5. 5. 雙擊每個元素 .看此表上註明,並修改其屬性 .Component HorizontalAlignment String TagTop Edit Text right 0 edit1Bottom Edit Text right 0 edit2Left Static Text center = text1Rigth Static Text right 0 resultPush-button center + pushbutton1
  6. 6.  function edit1_Callback(hObject, eventdata, handles)% hObject    handle to edit1 (see GCBO)% eventdata  reserved - to be defined in a future version of MLB% handles    structure with handles and user data (see GUIDATA)% Hints: get(hObject,String) returns contents of edit1 as text%        str2double(get(hObject,String)) returns contents of %        edit1 as a doublenum = str2double(get(hObject,String));if isnan(num)    num = 0;    set(hObject,String,num);    errordlg(Input must be a number, Error)endhandles.edit1 = num;guidata(hObject,handles)
  7. 7. function edit2_Callback(hObject, eventdata, handles)                          % hObject    handle to edit2 (see GCBO)                          % eventdata  reserved - to be defined in a future version of MLB                          % handles    structure with handles and user data (see GUIDATA)                          % Hints: get(hObject,String) returns contents of edit2 as text                          %str2double(get(hObject,String)) returns contents of                           %edit2 as a double                          num = str2double(get(hObject,String));                          if isnan(num)                          num = 0;                          set(hObject,String,num);                          errordlg(Input must be a number, Error)                          end                          handles.edit2 = num;                          guidata(hObject,handles) 
  8. 8. --- Executes on button press in pushbutton1.function pushbutton1_Callback(hObject, eventdata, handles)% hObject    handle to pushbutton1 (see GCBO)% eventdata  reserved - to be defined in a future version of MLB% handles    structure with handles and user data (see GUIDATA)addition = handles.edit1 + handles.edit2;set(handles.result, String, addition);
  9. 9.  % --- Executes just before adder is made visible.function adder_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.% hObject handle to figure% eventdata reserved - to be defined in a future version of MLB% handles structure with handles and user data (see GUIDATA)% varargin command line arguments to adder (see VARARGIN)% Choose default command line output for adderhandles.output = hObject;num = 0;handles.edit1 = num;handles.edit2 = num;% Update handles structureguidata(hObject, handles);% UIWAIT makes adder wait for user response (see UIRESUME)% uiwait(handles.figure1);
  10. 10. 最後的結果是
  11. 11. 二 . 卡的魔術 我們現在要招 callback 功能要開發另一個電腦卡在MatlabGUI 。步驟1.打開 MATLAB command: >> guide blank GUI2.拖放 :3.1 個 ‘ axes’ 按鈕4. 1 個 ‘ static text ’ 按鈕5.1 個 ‘ push button’ 按鈕
  12. 12.  雙擊每個元素 .看此表上註明,並修改其屬性 .Tag axes1 text1 pushbutton1Position 4 6 75 22 84 15 23 8 83 6 22 2.5FontSize 10 10FontWeight bold boldHorizontalAllignment left leftStringChoose a cardDon’t forget it!Concentrate...Continue...
  13. 13. • 現在你應該有類似此圖片* 設置這些屬性存你的身材名稱為“ trick2.fig”.* 編輯回調函數 callback-functions
  14. 14. * 編輯回調函數 callback-functions % --- Executes just before trick2 is made visible.function trick2_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% varargin command line arguments to trick2 (see VARARGIN) % Choose default command line output for trick2handles.output = hObject; clcaxes(handles.axes1);bg = imread(trick2_001.jpg);image(bg);axis off; % Update handles structureguidata(hObject, handles); % UIWAIT makes trick2 wait for user response (see UIRESUME)% uiwait(handles.figure1);
  15. 15.  For the callback associated with the push-button, complete it likethis: % --- Executes on button press in pushbutton1.function pushbutton1_Callback(hObject, eventdata, handles)% hObject handle to pushbutton1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)str = {I see it clearly... ;;;I have made your card vanish!!};set(handles.text1,String,str);axes(handles.axes1);bg = imread(trick2_002.jpg);image(bg);axis off; set(handles.pushbutton1,Visible,off)
  16. 16.  最後,我們下載中心的圖像從這個網頁http://www.matrixlab-examples.com/card-trick.html運行文件“ trick2.m”
  17. 17.  點擊“繼續”按鈕,我們得到
  18. 18. 結論MATLAB 是一種非常有用的,非常強大的一個軟件。 我們可以使用 MATLAB 的應用範圍,包括信號處理和通信,圖像和視頻處理,控制系統,測試和測量,計算金融學,計算生物學,機械和土木工程等 ...但 matlab 的也有一些缺點。它使用了大量的內存和較慢的計算機上。
  19. 19. references http://www.mathworks.com/products/matlab/ http://www.matrixlab-examples.com/card-trick.html http://stackoverflow.com/questions/179904/what-is-matlab-good-for-why-is-it-so-used-by-u http://en.wikipedia.org/wiki/MATLAB http://www.mccormick.northwestern.edu/docs/efirst/matlab.pdf http://answers.yahoo.com/question/index?qid=20100605122719AAlCO8T http://www.ee.columbia.edu/~marios/matlab/matlab_tricks.html http://www.math.umd.edu/undergraduate/schol/matlab/description.html

×