Matlab Plot
Plot
plot(xdata, ydata);
Create a new figure window
figure;
Use the same figure window
hold on;
ex)
figure; hold on; plot(1:10,1:10); plot(1:10,2:11);
Label
xlabel('xlabel');
ylabel('ylabel');
Control axis scaling
axis([xmin xmax ymin ymax]);
Title
title('title');
Title can show a math equation using TeX-like notation.
Legend - Display names for plotting lines
figure; hold on;
plot(1:10);
plot(2:11);
plot(3:12);
legend('1:10', '2:11', '3:12', 'Location', 'SouthEast');
Color and Marker
| y | yellow |
| m | magenta |
| c | cyan |
| r | red |
| g | green |
| b | blue |
| w | white |
| k | black |
figure; hold on; plot(1:10, 'r'); plot(2:11, 'g');
| . | point |
| o | circle |
| x | x-mark |
| + | plus |
| - | solid line |
| * | star |
| : | dotted line |
| -. | dashdot line |
figure; hold on; plot(1:10, 'ro'); plot(2:11, 'g+');
doc LineSpec
Change color and marker after plotting
set(findobj(gca,'Type','line','Color',[0 0 1]),'Color',color{i},'Marker',marker{i});
figure; hold on; plot(1:10); set(findobj(gca,'Type','line','Color','blue'),'Color','red','Marker','+'); plot(2:11); set(findobj(gca,'Type','line','Color','blue'),'Color','green','Marker','o'); plot(3:12); set(findobj(gca,'Type','line','Color','blue'),'Color',[0 0 0],'Marker','*'); % [r, g, b] is also okay for color
Do not use blue line.
Text property
http://nf.nci.org.au/facilities/software/Matlab/techdoc/ref/text_props.html
Change plotting window size and remove outside plotting window
size = [256 256]; fig = figure; plot(1:10); pos = get(fig, 'Position'); set(fig, 'Units', 'pixels', 'Position', ... [pos(1), pos(2)+pos(4)-size(1), ... size(2), size(1)]); set(gca,'Position', [0 0 1 1], 'Visible', 'off');
Grid
grid
log plot
loglog semilogx semilogy
Change Labels of coordinates (Tick)
tau = [0 0.1..0.9 0.91..0.99 0.991..0.999 0.9991..0.9999]; y = tau.^2; % function of tau plot(1:length(tau), y); set(gca,'XTick',[1 10 19 28 37]); set(gca,'XTickLabel','0|0.9|0.99|0.999|0.999');
doc % Graphics > Axes Properties > Individual Axis Control
