Präsentation herunterladen
Die Präsentation wird geladen. Bitte warten
Veröffentlicht von:Raginmund Zartman Geändert vor über 10 Jahren
1
Matlab Einführung Tobias Wunner 16. Oktober 2006
2
Matlab eine Einführung
Vorteile Interpreter und interaktive Befehlseingabe Schnelles Implementieren von wissenschaftlichen Methoden Gutes Hilfesystem >> lookfor 'sum' TRACE Sum of diagonal elements. CUMSUM Cumulative sum of elements. SUM Sum of elements. ...
3
Matlab eine Einführung
Vorteile Interpreter und interaktive Befehlseingabe Schnelles Arbeiten zum Entwickeln von Programmen Gutes Hilfesystem >> help sum SUM Sum of elements. S = SUM(X) is the sum of the elements of the vector X. If X is a matrix, S is a row vector with the sum over each ...
4
Matlab eine Einführung
Vorteile Modulorientiert / Offen Sämtliche Matlabskripte sind einsehbar >> edit sum
5
Matlab eine Einführung
Vorteile Erweiterbar C oder FORTRAN Code durch mex Bibliotheken
6
Matlab eine Einführung
Vorteile Profiler ab Version 7! Hilft beim Auffinden von Ressourcen-Verbrauchenden Programmteile
7
Matlab eine Einführung
Vorteile Umfangreiche Softwarepakete vorhanden z.B.Toolboxes Image Processing Toolbox Neural Network Toolbox Hier findet ihr alles was ihr nicht findet… :)
8
Matlab eine Einführung
Nachteile Nicht Objektorientiert (kein JAVA) Effiziente Programme nur durch Vektorisierung for x=1:5 y = sqrt(x); end >> x=1:5 X = >> y=sqrt(1:5); statt „Umdenken“
9
Matlab eine Einführung
Nachteile Fast Alles ist erlaubt! Keine Variablendeklaration nötig Variablenneubelegungen (Typänderung) Funktionen mit gleichen Ein- und Ausgabeparametern >> x=2 >> x=‘super‘ function x = myfun(x) ... x = x*2;
10
Matlab eine Einführung
Nachteile Fast Alles ist erlaubt! Sogar Build-In Matlab Funktionen können als Variablen genutzt werden => ACHTUNG tötet eingebaute Funktionen!!! >> sum = 1:5; >> sum([ ]) 3 4 % intuitiv erwartet =15 >> who % zeigt alle variablen im speicher an ans sum >> tmp = sum % sichern von variable sum >> clear sum % löschen von variablesum >> sum(tmp) % richtig! 15
11
Matlab eine Einführung
MATLAB starten UNIX z.B. Remote via Putty Windows option matlab matlab –nojvm -nodisplay
12
Matlab eine Einführung
Handwerkzeug zum starten Arbeitsverzeichnis >> pwd >> ls >> cd projekt1 Variablen im Speicher >> who Variablen löschen/speichern >> clear y >> save dateiname >> load dateiname History Cursor
13
Matlab eine Einführung
Matrizen Beliebige Matrizen >> [ ; ] Spezielle Matrizen >> eye(3) >> ones(2,4) >> zeros(1,3) Zufallszahlen >> rand(3) >> rand(100,100)
14
Matlab eine Einführung
Matrizen indizieren Dimension >> x=rand(3,4) % M-by-N Matrix >> size(x,1) % M = Zeilen >> size(x,2) % N = Spalten Alle Elemente als Liste >> x(:) k-tes bis Letztes Element >> y(k:end)
15
Matlab eine Einführung
Matrizen indizieren Mit Logik >> x=2:7 >> x>4 Indizes ausgeben >> find(x>3) 5 6 7
16
Matlab eine Einführung
Vergleichsoperatoren kleiner/größer <,> gleich/ungleich ==,~= größergleich >= Logische Operatoren Und & Oder | Nicht ~
17
Matlab eine Einführung
Matrizen sortieren/umformen sortieren >> x=6:-1:1 >> sort(x) umformen >> reshape(x,2,3) 1 3 5 2 4 6
18
Matlab eine Einführung
Matrix Algebra Kronecker Produkt >> kron([1 1 1],[1 2 5]) 1 1 1 2 2 2 5 5 5 Weiter nützliche Matrixoperationen >> help matfun
19
Matlab eine Einführung
Komponentenweise Operationen Inneres Produkt >> x=[1 -1]‘ (x ist hier >> x‘*x Spaltenvektor!) 2 Äußeres Produkt >> x*x‘ 1 -1 -1 1
20
Matlab eine Einführung
Vektormanipulationen Eintragsweise Operationen >> [1 2 3].*[ ] >> [ ]./[ ] >> [2 4 8].^2
21
Matlab eine Einführung
Programmierung Schleifen for i=[ ] sprinft(´Round%d\n´,i); end while BEDINGUNG ...
22
Matlab eine Einführung
Programmierung Abbruch von Schleifen for i=1:10 ... if (error<.1) break; % bricht Schleife ab end
23
Matlab eine Einführung
Programmierung Bedingungen if BEDINGUNG ... end else
24
Matlab eine Einführung
Datentypen Arrays matrix = [‘Peter‘,‘Hans‘] PeterHans matrix = [‘Peter‘;‘Hans‘] geht nicht! Cells cell = {‘Peter‘,‘Hans‘} m = char(cell) Peter Hans Lösung >> m(2,:) Hans >> cell{2}
25
Matlab eine Einführung
Datentypen Cells -> beliebiege Datentypen cell2 = {12,cell,m} cell2{3} Peter Hans Ähnliche Idee bei Struct struct1.a = cell2; struct1.b = rand(10,10); struct1.a{2}{3}(2,:) % Zugriff auf Hans
26
Matlab eine Einführung
Ein-/Ausgabe disp(‘Hello World‘); % Einfache Ausgabe sprinft(‘Zahl=%d\n‘,x); % Formatierte Ausgabe x = input(‘Zahl eingeben:‘,x); % Einfache Eingabe S = ‘1 2 3‘; x = sscanf(S,‘%f‘); % Formatierte Eingabe
27
Matlab eine Einführung
Grafische Ausgabe von Daten neues Ausgabefenster öffnen figure Daten in einem 2D Bild ausgeben x=rand(10,10); x2=x*x‘; figure, imagesc(x2), colorbar sc = scaled image Skala Kovarianzmatrix
28
Matlab eine Einführung
Grafische Ausgabe von Daten Funktionen Plotten plot(XVALUES,YVALUES) xval = 0:.1:30 yval = sin(3.*cos(xval)) plot(xval,yval,‘r‘) Mehrere Funktionen yval2 = sin(xval) plot(xval,yval,xval,yval2) oder plot(xval,yval,‘:b‘) hold on plot(xval,yval2,‘r‘)
29
Matlab eine Einführung
Grafische Ausgabe von Daten 3D Plot von Oberflächen (surfaces) x = imread(...); surf(x);shading flat;
30
Matlab eine Einführung
Ähnliche Präsentationen
© 2024 SlidePlayer.org Inc.
All rights reserved.