Friday, November 30, 2007

matlab funktion zum formatieren von ticklabels


diesmal auf deutsch, eine kleine Funktion, um in matlab die Achsennumerierung "auf deutsch" umzusetzen.
das heisst, es wird "." als tausender separator benutzt.

die funktion macht aus
0 -> 0
1000 -> 1.000
1111 -> 1.111
1110 -> 1.110
1100 -> 1.100


hier ist die funktion:

function out = StrFormat(in)

%% 1000
%% 100
c= (in - t*1000);

%% merge
for i=1:1:length(in)
str_t = num2str(t(i));
str_c = num2str(c(i));

switch length(str_c)
case 3
% alles ok
case 2
str_c(3) ='0';
case 1
str_c(2:3) = '0';
disp('error in switch str_c')

out{i} = [str_t '.' str_c ];
if out{i} == '0.000'
out{i} = '0';

wie funktioniert die Funktion? Hier eine kleine Hilfe:


very simple sound (signal) generation in matlab and vba

hi people.

for my scripts, i sometimes put a sound-generating function at the end, that lets me know the script is finished.

to do this in matlab, use this command


in vba, use


Tuesday, November 27, 2007

at the moment i'm not working with LaTeX

Hi people, at the moment i'm not working with LaTeX. at office, i HAVE to work with word :-(

but i steel active in the LaTeX world, i will post here as soon as i have more time (uff. that's the big question... when do i have time???)

have a while


check if a excel chart as a legend in vba

hi people, i had a problem with a vba script and i needed to check if a chart in excel had a legend active.

for that, use this code:

If ActiveChart.HasLegend Then
Selection.AutoScaleFont = False
With Selection.Font
.Name = "Arial"
.FontStyle = "normal"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = True
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.Background = xlAutomatic
End With

'With Selection.Border
' .Weight = xlHairline
' .LineStyle = xlAutomatic
'End With
Selection.Shadow = True
End If

Thursday, November 22, 2007

my Style (report) for LaTeX documents

Hi, i have uploaded my style for latex documents. it's a modified version of the report class. i use it for my thesis at the university of munich (technische universität münchen, TUM).

you can find the description of the files and the files at my latex webpage:

if you have any question, feel free to contact me.

carpetplot with matlab - part 2

hi, i have made some modifications to the carpetplot function.

here they are

function carpetplot(data,FigNr)

max_zeilen = 24;
while spalte <= 365, while zeile <= max_zeilen, DATA(zeile,spalte)=data(i); zeile=zeile+1; i=i+1; end spalte=spalte+1; zeile=1; end %DATA=flipud(DATA); x=[1:1:365]; y=[0:1:23]; %% figure(FigNr) clf axes1 = axes(... 'FontSize',12,... 'LineWidth',1,... 'Box','on',... 'Parent',figure(FigNr),... 'YDir','reverse',... 'YTick',[0 4 8 12 16 20 ],... 'PlotBoxAspectRatio',[1 1 1]); xlabel(axes1,'Tage im Jahr'); ylabel(axes1,'Uhrzeit'); grid(axes1,'off'); hold(axes1,'all'); set(gca,'XLim',([1 365]),'YLim',([0 23]))%,'ZLim',([-20000 -5000])) surf(x,y,DATA,'EdgeColor','none',... 'LineWidth',1,'Parent',axes1); view(0,90) colorbar('Fontsize',12) annotation(gcf,'textarrow',[0.9 0.9],[0.7723 0.8215],... 'TextEdgeColor','none',... 'TextRotation',90,... 'FontSize',12,... 'String','Tempeartur in °C',... 'HeadStyle','none',... 'LineStyle','none');

Monday, November 19, 2007

copy as picture from excel

Hi people.

a new trick: in excel you can copy a selection "as picture" into the clipboard. to do this, just select the table you whant to copy (or the range) and hold on shift. then click on edit (continue holding shift) and you'll see something like "picture copy" (sorry, my excel is in german, i don't know what's the name for this function in english).... there you are.

another posibility is to create a macro and give him a shortcut. put this single line in the macro:

Selection.CopyPicture Appearance:=xlPrinter, Format:=xlPicture

and that's it.

enjoy it

Friday, November 16, 2007

Thermodynamic properties of water and steam

Hi people, today i found 2 usefull packages for matlab if you plan to calculate the thermodynamic properties of water with matlab. I have not test the packages yet.

you can find them here:

have a while

Wednesday, November 14, 2007

PDF documents on matlab

Hi people,

today i discovered this place, where you can find many documents about matlab. it is posible that you can download this documents from the mathworks, but i have not seen them (i have not search for them anyway....).


Monday, November 12, 2007

excel in german has diferent names for functions

Hi people. for all the people working with the german version of excel:
this excel file shows you many functions, and their name in german and english. very usefull!!!!

Speed up vba

Hi again.

a small hint for vba users. if you move large amount of data and your script takes too long to run, consider putting the following lines at the beginning of the script:

Application.ScreenUpdating = False

Application.Calculation = xlCalculationManual

at the end of the script, you should put this lines:
Application.ScreenUpdating = True

Application.Calculation = xlCalculationAutomatic

"add sheets after". How to add sheets in excel

Hi people. if you have the problem that excel always create new sheets at the left side of the current one, you have to try this script. just add it to your personal vba module and make a shortcut for the keyboard.

the code is:

Sub add_sheets_after()
Dim mySheet As String
Dim myNewSheet As String
mySheet = ActiveSheet.Name
myNewSheet = ActiveSheet.Name
Sheets(myNewSheet).Move After:=Sheets(Sheets.Count)
End Sub

change the Cell mode in excel from A1 to R1C1 using vba

To do this, you can write a simple macro as follows:

Sub bezugsart()
' bezugsart Makro
' Makro am 30.10.2007 von TMezger aufgezeichnet

If Application.ReferenceStyle = xlA1 Then
With Application
.ReferenceStyle = xlR1C1
End With


With Application
.ReferenceStyle = xlA1
End With
End If

End Sub

Friday, November 9, 2007

carpet plots with matlab

if you are planning to plot some data as carpet plot, you can use matlab. there is a simple trick to do that.

in this example, i create a carpet plot for a 35040 vector.
first, i convert the data into a 365x96 matrix. then i plot it using the surf command, and change the view point with "view(0,90)"
that's all!
here the function:

function carpetplot(data,FigNr,colormap)

max_zeilen = 24*4;
while spalte <= 365,
while zeile <= max_zeilen,

axes1 = axes(...
% 'CLim',[-20000 -5000]);
xlabel(axes1,'Tag im Jahr');

set(gca,'XLim',([1 365]),'YLim',([0 (24-1/(4*60))]))%,'ZLim',([-20000 -5000]))


colorbar1 = colorbar('peer',...
'XLim',[-0.5 1.5], 'YLim', [-20000 -5000],...
'CLim',[0 6]);


% set(axes1,'CLim', [0 4])
take a look to the part 2 of the carpet plot function

documentation for hgexport

if you take a look at the help in matlab, you won't find a good documentation of the function hgexport. this is because the function is steel being only for internal proposes.

to see how this function work, take a look at the file itself:

>> edit hgexport

Thursday, November 8, 2007

export a figure using a style from the matlab command line


i was wondering if there is a posibility to export a figure directly from the commandline using matlab using a predefined style.

well... there is.

i have made a function (inspired on this link) called fig2png where you can do it (at the end of this post). To call the function, use this:


function fig2png(figname,filename,sname)
% 08.11.2007
%this function exports the figure figname to a file filename, using the
%style sname
% the style hast to be in your matlab home!!!

%% check if figure is docked
if strcmpi(get(figname,'WindowStyle'),'docked')
undock = 1;
undock = 0;
%% set style

%% undock
if undock == 1
disp(['undocking figure ' figname])
%% export to filename
disp('file written')
%% export to clipboard
disp('exported to clipboard')
%% dock aggain if it was docked
if undock == 1
disp(['docking figure ' figname ' aggain'])

convert NaN to zeros

the problem with large amount of data is, you don't have an overview of the data.

for example, if you have NaN in your data, and you plot it, it is posible that you don't see where this NaNs are. a good way to find them is using max and min.

if you have some NaNs in your data, and you whant to convert them to zeros (or whatever), use the following command:

data(isnan(data)) = 0; % convert NaN into 0!!!!
have a while!