155GIT1 / 9. cvičení

Z GeoWikiCZ

Grafy funkcí

Náplň cvičení

  1. grafické okno figure
  2. grafy funkcí plot(), subplot(), axis()

Ukázky

Grafické okno

figure
figure    # -> 2
figure(4) # -> 4

Grafy funkcí

x = [0:3:360];
y = sin(x*pi/180);
plot(x, y);
%
% nové okno
figure(2)
plot(x, y, 'r+')
%
% více grafů najednou
z = cos(x*pi/180);
plot(x, y, '--b', x, z, ':k');
plot(x, y, '--b', x, z, ':k')

Popisky grafů

figure(3)
hold on
plot(x,y,'m');
plot(x,z,'b');
title('Funkce sinus a cosinus')
xlim([0 360]);
ylim([-1.2 1.2]);
xlabel('argument ve stupnich')
ylabel('funkcni hodnota')
% V Matlabu lze pouzit i vhodnejsi umisteni 'Best' anebo
% legend('sinus','cosinus', -1) coz umisti legendu mimo plochu grafu
legend('sinus','cosinus', 'Location', 'SouthWest')
box on
grid on
plot([0 360],[0 0],'k')
hold off
Graf s popisky

Více grafů v jednom okně

x = 1:100;
figure
% první
subplot(2, 2, 1)
plot(x, x)
% druhý
subplot(2, 2, 2)
plot(x, sqrt(x))
% třetí
subplot(2, 2, 3)
plot(x, log(x))
% čtvrtý
subplot(2, 2, 4)
plot(x, x.^2)
subplot()

Omezení oblasti grafu

x = 0:0.1:5;
y = exp(x);
% celý graf
subplot(2, 1, 1)
plot(x, y)
% výsek x <1, 2>; y <0, 10>
subplot(2, 1, 2)
plot(x, y)
axis([1,2,0,10])
axis()

= Graf s orientaci os v S-JTSK

% nacteni dat
vstup = fopen('body.txt','r');
P = fscanf(vstup,'%f',[3 inf]);
BYX = P';
fclose(vstup);

% vypocet smerniku
stan = [4001 730288.89 1054582.63]; % cb Y X (stanovisko)
DY = BYX(:,2) - stan(2);
DX = BYX(:,3) - stan(3);
sig = atan2(DY,DX);     % v radianech
sig = sig*200/pi;
% prevod smerniku do intervalu <0,400>
for i=1:length(sig)
    if sig(i)<0
        sig(i)=sig(i)+400;
    end
end
sig  % kontrolni zobrazeni vypoctenych hodnot smerniku 

% kontrolni graf v JTSK
figure(6)
x = BYX(:,3);
y = BYX(:,2);
cb = BYX(:,1);
plot(-y,-x,'.r',-1*stan(2),-1*stan(3),'.b');
for i=1:size(BYX,1)
    cislab = num2str(cb(i));      % prevod numericke hodnoty na format string
    text(-y(i)+0.4,-x(i),cislab);
end
cislos = stan(1);
text(-1*stan(2),-1*stan(3),num2str(cislos));
title('body v JTSK');
xlabel('Y'); ylabel('X');

Úlohy