Seite 1 von 2
Matlab Code einbinden
Verfasst: Do 25. Okt 2012, 18:18
von Ralph_P
Hallo,
Code ist zwar keine Tabelle und keine Grafik, aber ich dachte, hier passt es noch am besten rein.
Hat jemand schon mal in seine wissenschaftliche Arbeit Matlab-Code eingebunden und würde mir seinen Latex-Schnipsel zur Verfügung stellen?
Ich benutze derzeit die listings-Umgebung mit language=Matlab, das Ergebnis ist aber nicht zufrieden stellend (schaut nicht schön aus).
Ich würde mich freuen!
Ralph_P
Verfasst: Do 25. Okt 2012, 18:23
von bloodworks
Hi wenn du uns an deinen bisherigen Versuchen in Form eines Minimalbeispiel [2] teilhaben lässt kann man dir vielleicht auch helfen ohne selbiges selbst zu Basteln.
Verfasst: Fr 26. Okt 2012, 11:31
von Ralph_P
Hi,
gerne, ja. Ich dachte nur ein Start "von ganz vorne" wäre gut, weil meine Versuche so gar nicht schön aussehen
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{subfigure}
\usepackage{amsmath}
\usepackage[intoc]{nomencl}
\usepackage{listings} \lstset{numbers=left, numberstyle=\tiny, numbersep=5pt} \lstset{language=Matlab} % Code einbinden
\begin{document}
\begin{lstlisting}[caption=Beispielcode]{Name}
function [X,U] = Test(e)
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
X= 3* e;
U = e/2;
\end{lstlisting}
\end{document}
Verfasst: Fr 26. Okt 2012, 12:15
von bloodworks
In Anlehnung an den Standard Stil von ML 2011. Dein Hauptproblem ist aber, dass deine Zeilen zu lang sind für eine Seite. Da musst du dann halt überlgen wie du das machen willst. (Wobei ich mich ernsthaft frage wie man mit Matlab so eine Definitionsorgie hinbekommt. Im Normalfall reicht es aus die Matrix einmal zu definieren.)
\documentclass{article}
\usepackage{xcolor, showframe}
\definecolor{mlgreen}{rgb}{.035,.6,.251}
\definecolor{mlviolett}{rgb}{.643,.259,.804}
\usepackage{listings}
\lstdefinestyle{mlab}{language=Matlab, numbers=left, numberstyle=\tiny,%5
basicstyle={\ttfamily},%
keywordstyle={\color{blue}},%
commentstyle=\color{mlgreen},%
stringstyle=\color{mlviolett},%
breaklines=true,
} %
\begin{document}
\begin{lstlisting}[style=mlab, caption=Beispielcode]{Name}
function [X,U] = Test(e)
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
a = 1; b=2; c=3; d=4; e=5; f=6; g=7;a = 1; b=2; c=3; d=4; e=5; f=6;
X = 3*e;
U = e/2;
% definigs range
x=[-2:.1:2];
% computing y
y=x.^2;
%2d plot
plot(x,y)
disp('done')
\end{lstlisting}
\end{document}
Verfasst: Fr 26. Okt 2012, 14:14
von Ralph_P
Hi bloodworks,
sehr sehr cool, ich kann dir gar nicht genug danken!
(Die Definitionsorgie sollte nur gewährleisten, dass der Beispielcode über mehrere Seiten geht - mein richtiges Skript sieht natürlich anders aus

)
Verfasst: Mo 26. Aug 2013, 16:13
von Peter_Pan_2
Hi,
der Matlab Code sieht echt gut aus! Aber wie kann ich dafür sorgen, dass die Rahmen auch nur den Matlab Code umranden? Bei mir werden jetzt alle Seiten eingerahmt!
Gruß
Peter Pan
Verfasst: Mo 26. Aug 2013, 16:44
von Noch so einer
Verfasst: Di 27. Aug 2013, 09:13
von Peter_Pan_2
Hi,
ich habe den Code oben mit Copy & Paste eingefügt, das ist mein Minimalbeispiel...!
Wenn ich die Main kompiliere wird jedoch nicht nur das Kapitel mit dem Matlab Code, sondern alles eingerahmt.
Gruß,
Peter Pan
Verfasst: Di 27. Aug 2013, 09:22
von Noch so einer
Du meinst die Visualisierung der Seitenelemente mit Hilfe von showframe in bloodworls Beispiel? Das Paket wurde von bloodworks nur zu Demozwecken (Test, ob der Mathlab-Coide in die Satzspiegelbreite passt) eingebunden. Das solltest Du für reale Dokumente weglassen. Wenn Du listings eingerahmt haben willst, dann lies die Anleitung zum Paket listings.
Verfasst: Di 27. Aug 2013, 09:28
von Noch so einer
PS: Das Paket
mdframed könnte für Dich in diesem Zusammenhang eventuell auch noch von Interesse sein. Siehe dessen Anleitung, beispielsweise auch das Beispiel mdframed-example.texsx, das in Abschnitt 10 erwähnt wird.