Cavolo è passato più di un mese dall'ultimo post...
Anche lo sviluppo del sito è rallentato dal ritmo frenetico di lavoro e università... piano piano cercherò di fare tutto...

Tornando all'oggetto del post, visto che devo fare altre relazioni su dati elaborati con Matlab, ne ho approfittato per sistemare la mia funzione per creare tabelle!

Ed ecco la versione 2.0:
function latex_table(var,dec,title,width)

% LATEX_TABLE v. 2.0
%
% latex_table(var,dec,)
%
% Export var as latex table
%
% Necessary Parameters:
% var is an array of floats
%
% dec is the number of decimals of the values of var
%
% Optional Parameters:
% title is used for the first row of the table, it must be a cell array
% with the same number of elements of the number of var's columns
%
% width is the tabularx arguments, default value is \textwidth
%
% Created by Andrea Vannuccini - 2008.04

[r c] = size(var);

fprintf('\n\t ATTENZIONE: ricordati di inserire nel preambolo del documento:')
fprintf('\n\t\t\\usepackage{tabularx}')


fprintf('\n\n\t --- LATEX TABLE OUTPUT BEGIN --- \n\n');

if nargin ~= 4
width = '\textwidth';
end

fprintf('\\newcolumntype{U}{>{\\centering\\arraybackslash}X}\n');
fprintf('\\begin{tabularx}{%s}{|*{%d}{U|}}\n',width,c);
fprintf('\\hline \n');

if nargin > 2
for k = 1:c
if k == c
fprintf('%s \\\\ \\hline \n', title{k});
else
fprintf('%s & ', title{k});
end
end
end

for i = 1:r
fprintf('\t')
for k = 1:c
if k == c
fprintf(['%.' num2str(dec) 'f \\\\ \\hline \n'],var(i,k));
else
fprintf(['%.' num2str(dec) 'f & '],var(i,k));
end
end
end

fprintf('\\end{tabularx}\n')
fprintf('\n\t --- LATEX TABLE OUTPUT END ---\n\n\n');


Esempio:

I comandi:
a = 1:5;
b = 5:-1:1;
title = {'\bfseries a' '\textit b'};
latex_table([a' b'],2,title,'.5\textwidth');


Restituiscono a video:
  ATTENZIONE: ricordati di inserire nel preambolo del documento:
\usepackage{tabularx}

--- LATEX TABLE OUTPUT BEGIN ---

\newcolumntype{U}{>{\centering\arraybackslash}X}
\begin{tabularx}{.5\textwidth}{|*{2}{U|}}
\hline
\bfseries a & \textit b \\ \hline
1.00 & 5.00 \\ \hline
2.00 & 4.00 \\ \hline
3.00 & 3.00 \\ \hline
4.00 & 2.00 \\ \hline
5.00 & 1.00 \\ \hline
\end{tabularx}

--- LATEX TABLE OUTPUT END ---


Che compilato restituisce questa tabella:



Ho deciso di utilizzare il pacchetto tabularx che permette di creare tabelle a dimensione fissa e di regolare automaticamente la larghezza delle colonne.

Spero che la nuova versione vi allievi le fatiche politecniche!!
Come di consueto commenti e suggerimenti sono bene accetti!

Ciao a tutti,
Andrea

EDIT:
Ho deciso di spostare future revisioni su:
MATLAB Central File Exchange! Qui potrete trovare l'ultimissima versione!
Ciao a tutti!!

1 commento:

Unknown ha detto...

uoooooooooooooooooooooooooo!!!!

ciaooo ;)