155GIT1 / 9. cvičení: Porovnání verzí
mBez shrnutí editace |
|||
Řádek 96: | Řádek 96: | ||
{{fig|octave-graf-3|<code>axis()</code>}} | {{fig|octave-graf-3|<code>axis()</code>}} | ||
* graf s orientaci os v JTSK | |||
<source lang=octave> | |||
% 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 | |||
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 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)); | |||
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'); | |||
</source> | |||
== Úlohy == | == Úlohy == | ||
* [[155GIT1 / 9. cvičení / Příklady|9. cvičení - příklady]] | * [[155GIT1 / 9. cvičení / Příklady|9. cvičení - příklady]] |
Verze z 20. 4. 2016, 09:16
Grafy funkcí
Náplň cvičení
- grafické okno
figure
- grafy funkcí
plot(), subplot(), axis()
Ukázky
Grafické okno
figure
figure # -> 2
figure(4) # -> 4
Grafy funkcí
plot()
• argumenty
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
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

subplot()
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()
axis()
- 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 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
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 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));
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');