Contents

Called Functions

A25 4D PLOT

close all
x=linspace(-2,2,100);
y=linspace(-2,2,100);
z=linspace(-2,2,100);

f = @(x,y,z,t) (sin(t.*x+y)+cos(3*pi*t*z.*x));

[X,Y,Z] = meshgrid(x,y,z);

xslice = 0; yslice = 1; zslice = 0;
for t = linspace(0,10,50)
    F = f(X,Y,Z,t);
    H=slice(X,Y,Z,F,xslice,yslice,zslice);
    set(H,'EdgeColor','none')
    pause(0.1)
end

A26 READ

clear all

n=69;

W = readWetter('wetter.txt');

W(3)
ans = 

    name: 'Muenchen'
    temp: 12.9000
     rel: 83.1000

A27 EDIT

for i =1:length(W)
    W(i).abs = GetAbsF(W(i));
    W(i).wertung = WetterWertung(W(i));
end

W(3)
ans = 

       name: 'Muenchen'
       temp: 12.9000
        rel: 83.1000
        abs: 9.3674
    wertung: 'frisch'

A28 WRITE

MyOut(W,'erg.txt')
GetAbsF
function absF = GetAbsF(w)
    load('MaxF.mat');
    low = round(w.temp-0.5)+1;
    top = round(w.temp+0.5)+1;
    fac = w.temp-low+1;

    MF = MaxF(low)*(1-fac) + fac*MaxF(top);
    absF = w.rel*MF/100;

end
MyOut
function MyOut(W,filename)
% open the file
fid = fopen(filename,'w');
fprintf(fid,'       Stadt      Temp.   Rel.F.   Abs.F.       Ansage\n');
for i =1:length(W)
    fprintf(fid,'%16s  %4.1f°C  %4.1f %%   %4.1f g/m^3   %s\n',...
            W(i).name,W(i).temp,W(i).rel,W(i).abs,W(i).wertung);
end
% close the file
fclose(fid);
end
WetterWertung
function wert=WetterWertung(w)
if w.temp < 10
    wert = 'kalt';
    return;
end
if w.temp < 18
    wert = 'frisch';
    return;
end
if w.temp < 25
    wert = 'warm';
    return;
end
if w.temp > 25
    wert = 'heiß';
    return;
end
end
readWetter
function W = readWetter(filename)
% open the file
fid = fopen(filename);

tline = fgetl(fid);
i=1;
while ischar(tline)
    W(i).name = sscanf(tline, '%s%');
    W(i).temp = sscanf(tline, '%*s %f°C');
    W(i).rel = sscanf(tline, '%*s %*f°C %f%%');

    tline = fgetl(fid);
    i = i+1;
end

% close the file
fclose(fid);

end