- - - - // Wykresy i grafika w Matlabie plot Wykresy Wykresy D Wykresy D Animacje i filmy Tworzenie interfejsu uŝytkownika GUI Ręczne Wspomagane (GUIDE) plot(y) plot(x,y,...) plot(x,y,linespec,...) plot(...,'nazwa _cechy', Wartość_cechy,...) h = plot(...) x = -pi:pi/:pi; y = tan(sin(x)) - sin(tan(x)); plot(x,y) - - - - - plot(x,y,'-rs','linewidth',,... Oznaczenia kolorów: Kształt punktów s square (prostokąt) Linia wykresu. punktowy 'MarkerEdgeColor','k',... 'MarkerFaceColor','g',... 'MarkerSize',) ; y m c r g b w k yellow magenta cyan red green blue white black d diamond (karo) v trójkąt w dół ^ trójkąt w góre < trójkąt w lewo > trójkąt w prawo p pentagram - ciągła o kółka : kropkowana -. kropka-kreska -- przerywana x x-owana h hexagram + plus * gwiazdki - - - - - Opis osi plot(x,sin(x)) xlabel('oś X') ylabel('oś Y') plot(x,sin(x)); xlabel('-\pi \leq \Theta \leq \pi','fontsize',6) ylabel('sin(\theta)','fontsize',6).8.6.8 Oś Y.. -. -. sin(θ ).6.. -. -. -.6 -.6 -.8 - - - - - Oś X -.8 - - - - - -π Θ π
sin(-π ) // title text gtext legend x = -pi:pi/:pi; plot(x,cos(x),'-ro',x,sin(x),'-.b') h = legend('cos','sin',); Uwaga: legendę moŝna edytować I przesuwać. Podobnie jak wszystkie elementy wykresu!! legend(h,'string','string',...) legend('string','string',...) h = legend(...).8.6. cos sin. x = -pi:pi/:pi; plot(x,cos(x),'-ro',x,sin(x),'-.b') h = legend('cos','sin',); -. -. -.6 -.8 - - - - - x=[:.:7]; plot(x,sin(x)) set(gca, 'Xlim',[,]).9.8.7.6...........6.7.8.9 set(gca) ALim ALimMode: [ {auto} manual ] AmbientLightColor Box: [ on {off} ] CameraPosition CameraPositionMode: [ {auto} manual ] CameraTarget CameraTargetMode: [ {auto} manual ] CameraUpVector CameraUpVectorMode: [ {auto} manual ] CameraViewAngle CameraViewAngleMode: [ {auto} manual ] CLim CLimMode: [ {auto} manual ] Color ColorOrder DataAspectRatio DataAspectRatioMode: [ {auto} manual ] DrawMode: [ {normal} fast ] etc... set x = -pi:.:pi; y = sin(x); plot(x,y) set(gca, 'FontSize',) set(gca,'xtick',-pi:pi/:pi) set(gca,'xticklabel',{'-pi','-pi/','','pi/','pi'}) xlabel('-\pi \leq \Theta \leq \pi') ylabel('sin(\theta)') title('plot of sin(\theta)') text(-pi/,sin(-pi/),'\leftarrow sin(-\pi\div)',... 'HorizontalAlignment','left') sin(θ). -. - Plot of sin(θ) -pi -pi/ pi/ pi -π Θ π set(gcf) Alphamap BackingStore: [ {on} off ] CloseRequestFcn: string -or- function handle -or- cell array Color Colormap CurrentAxes CurrentCharacter CurrentObject CurrentPoint Dithermap DithermapMode: [ auto {manual} ] DoubleBuffer: [ on {off} ]... etc
// Kilka wykresów na jednym układzie współrzędnych hold on / hold off figure figure(numer) subplot subplot(m,n,p) subplot(h) subplot('position',[left bottom width height]) h = subplot(...) subplot in = [....6]; out = [....9]; subplot(,,); plot(in) subplot(,,); plot(out) 6............ Inne typy wykresów semilogx 9 8 7 6 semilogy x = :.:; semilogy(x,.^x) 6 7 8 9 loglog x = logspace(-,); loglog(x,x.^7,'-s') grid on hist N = hist(y) dzieli na równomiernie rozłoŝonych przedziałów. Jeśli Y macierz działa w dół kolumny x = -.9:.:.9; y = randn(,); hist(y,x) - - - N = hist(y,m), M - skalar, dzieli na M słupków. n = hist(y,x), x-wektor [n,xout] = hist(...) n-zliczenia i połoŝenie słupków (xout). - - - Bar Y = round(rand(,)*); subplot(,,) bar(y,'group') title 'Group' subplot(,,) bar(y,'stack') title 'Stack' subplot(,,) barh(y,'stack') title 'Stack' subplot(,,) bar(y,.) title 'Width =.' 8 6 Group Stack 8 6 Stack Width =. [n,xout] = hist(...) n-zliczenia i połoŝenie słupków (xout). moŝna potem bar(xout,n) aby narysować histogram. Wykresy trójwymiarowe plot plot(x,y,z,linespec,...) t = :pi/:*pi; plot(sin(t),cos(t),t) grid on axis square. -. - - -..
... -. - -. -. -. -. // Mesh, meshgrid [X,Y] = meshgrid(-:.:, -:.:); Z = sin(x.^)+cos(y.^); mesh(x,y,z); axis([- - - ]) [X,Y] = meshgrid(-:.:); Z = peaks(x,y); meshc(x,y,z); meshc axis([- - - ]) meshz contour [X,Y] = meshgrid(:.:); Z = peaks(x,y); meshz(x,y,z) [X,Y] = meshgrid(-:.:,-:.:); Z = X.*exp(-X.^-Y.^); contour(x,y,z,);... -. - -. - - -. - -... colormap contour [X,Y] = meshgrid(-:.:,-:.:); Z = X.*exp(-X.^-Y.^); [C,h] = contour(x,y,z); clabel(c,h) colormap cool -. -. -. -. -. -. -........... [X,Y] = meshgrid([-:.:]); Z = X.*exp(-X.^-Y.^); contour(x,y,z,).... -. -. -. -. - - - -. - -... - - -. - -...
.8.6.. -. -. -.6 -.8 - -.8 -.6 -. -....6.8 -.8.6.. -. -. -.6 -.8 - - -.8 -.6 -. -....6.8 // surface getframe Animacje - getframe figure; surface(peaks) F = getframe F = getframe(h) F = getframe(h,rect) [X,Map] = getframe(...) movie movie(m) movie(m,n) movie(m,n,fps) movie(h,...) movie(h,m,n,fps,loc) movie(h,m,n,fps,loc) plot(fft(eye(k+))) Przykład animacji GUI plot(fft(eye(k+6))) for k = :6 plot(fft(eye(k+6))) axis equal M(k) = getframe; end movie(m,) Obiekty graficzne uicontrol uicontrol('propertyname',value,'propertyname,'value,...) hh=uicontrol('style','pushbutton','string','przycisk') set(hh) BackgroundColor Callback: string -or- function handle -or- cell array CData Position String Style: [ {pushbutton} togglebutton radiobutton checkbox edit text slider frame listbox popupmenu ] hh=uicontrol('style','pushbutton','string','przycisk')
// stophndl=uicontrol(... Callback 'Style','pushbutton',... 'Units','normalized',... 'Position',[xPos ypos-spacing btnlen btnwid],... 'Enable','off',... 'String','Stop',... 'Callback', moja_funkcja(x,y)'); uimenu uimenu('propertyname',propertyvalue,...) uimenu(parent,'propertyname',propertyvalue,...) handle = uimenu('propertyname',propertyvalue,...) handle = uimenu(parent,'propertyname',propertyvalue,...) Przykład uimenu f = uimenu('label', 'Moje'); uimenu(f,'label', 'Nowy rysunek','callback', 'figure'); uimenu(f,'label','zapisz','callback','save'); uigetfile / uiputfile uigetfile uigetfile('filterspec') uigetfile('filterspec','dialogtitle') uigetfile('filterspec','dialogtitle',x,y) [fname,pname] = uigetfile(...) [fname,pname] = uigetfile('*.m', Podaj nazwe pliku) uiputfile Okna dialogowe - inputdlg % zdefiniuj warunki pytania = {'Wprowadź rozmiar macierzy:', ' Nazwa mapy kolorów:'}; okno_tytul = 'Dane funkcji peaks'; ile_linii= ; def = {'','hsv'}; skalowanie = 'on' wynik = inputdlg (pytania, okno_tytul,ile_linii,def, skalowanie); 6
// GUIDE UWAGA: typ generowanego pliku zmienia się w kolejnych wersjach MATLABA 7
// % --- Executes on button press in pushbutton. function pushbutton_callback(hobject, eventdata, handles) % hobject handle to pushbutton (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) disp('napisz cos tam') plot([ ], 'Parent',handles.axes) % --- Executes during object creation, after setting all properties. % End initialization code - DO NOT EDIT % --- Executes just before guide_zliczanie_wlasna_zmienna is made visible. function guide_zliczanie_wlasna_zmienna_openingfcn(hobject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hobject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to guide_zliczanie_wlasna_zmienna (see VARARGIN) % Choose default command line output for guide_zliczanie_wlasna_zmienna handles.output = hobject; %DODANE-poczatek--------------------------------- handles.ile= % dodane nowe pole struktury handles z poczatkowa wartoscia %DODANE-koniec----------------------------------- % --- Executes on button press in pushbutton. function pushbutton_callback(hobject, eventdata, handles) % hobject handle to pushbutton (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %DODANE-poczatek--------------------------------- nr=handles.ile % ktory nr aktualny handles.ile=nr+ % ustaw kolejny nr guidata(hobject, handles) % odswiez strukture "handles" z nowym nr set(handles.text,'string',handles.ile); % wyswietl nowy nr %DODANE-koniec----------------------------------- 8