摘要: 本文是吴恩达 (Andrew Ng)老师《机器学习》课程,第六章《Octave教程》中第41课时《绘制数据》的视频原文字幕。为本人在视频学习过程中记录下来并加以修正,使其更加简洁,方便阅读,以便日后查阅使用。现分享给大家。如有错误,欢迎大家批评指正,在此表示诚挚地感谢!同时希望对大家的学习能有所帮助。
>> t=[0:0.01:0.98];
>> y1=sin(2*pi*4*t);
>> plot(t,y1)
>> t=[0:0.01:0.98];
>> y2=cos(2*pi*4*t);
>> plot(t,y2)
>> plot(t,y1)
#hold
#hold on
#hold off
#hold (hax, …)
#Toggle or set the "hold" state of the plotting engine which determines whether new graphic objects are added to the plot or replace the existing objects.
#hold on
#Retain plot data and settings so that subsequent plot commands are displayed on a single graph. Line color and line style are advanced for each new plot added.
#hold all (deprecated)
#Equivalent to hold on.
#hold off
#Restore default graphics settings which clear the graph and reset axes properties before each new plot command. (default).
#hold
#Toggle the current hold state.
#When given the additional argument hax, the hold state is modified for this axes rather than the current axes returned by gca.
#To query the current hold state use the ishold function.
>> hold on
>> plot(t,y2,"r")
>> xlabel('time')
>> ylabel('value')
>> legend('sin','cos')
>> title('my plot')
# Print a plot, or save it to a file
>> print -dpng 'myPlot.png'
>> ls
Volume in drive C is VtasSOE
Volume Serial Number is E269-0541
Directory of C:\ecosys\toolkits\prog\Octave
[.] 1.dat example1.m hello.mat myPlot.png
[..] cpu_eagappnso01.dat featuresX.dat hello.txt priceY.dat
8 File(s) 68,681 bytes
2 Dir(s) 44,109,111,296 bytes free
# Close figure window(s). When called with no arguments, close the current figure
>> close
# To avoid new figure replacing old one
>> figure(1);plot(t,y1)
>> figure(2);plot(t,y2)
# creates a figure with two separate axes, one displaying a sine wave and the other a cosine wave. The first call to subplot divides the figure into two plotting areas (two rows and one column) and makes the first plot area active. The grid of plot areas created by subplot is numbered in row-major order (left to right, top to bottom). After plotting a sine wave, the next call to subplot activates the second subplot area, but does not re-partition the figure.
>> subplot(1,2,1)
>> plot(t,y1)
>> subplot(1,2,2)
>> plot(t,y2)
>> doc axis
# With one output argument, limits = axis returns the current axis limits.
>> limits=axis()
limits =
0 1 -1 1
# axis ([x_lo x_hi y_lo y_hi])
>> axis([0.5 1 -1 1])
>> limits=axis()
limits =
0.50000 1.00000 -1.00000 1.00000
>>
>> A = magic(5)
A =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
# Add a colorbar to the current axes. A colorbar displays the current colormap along with numerical rulings so that the color scale can be interpreted.
# Query or set the current colormap.
# Note that followings are comma chaining commands/function calls
>> imagesc(A),colorbar,colormap gray;
>>
<end>