吴恩达机器学习笔记(六)–Octave/Matlab教程
学习基于:吴恩达机器学习
1.Basic operations ~=means ≠ \neq ̸= disp(sprint("...") just like the “printf()” in C “format long” restores the default to print a large number of digits. The same to “format short” A = [ 1 2; 3 4; 5 6 ] use this command to generate a matrix. V = 1:01:2 set V to the bunch of elements that start from 1, and increment steps of 0.1 til 2 ones(2,3) generate a matrix of all ones zeros(1,3) generate a matrix of all zeros rand(3,4) generate a matrix of all random numbers drawn from the uniform distribution between 0 and 1 randn(1,3) generate a Gaussian matrix at random eye(5) generate a unit matrix hist(w) plot a histogram of w help <the function you want to get more information about> size(m) returns the dimension of m. It is a 1*2 matrix length(m) returns the longer dimension of m 2. Moving data around pwd shows the current directory load features.dat who shows the variables in the workspace, while whos gives you the detailed view clear features delet the variable save filename.mat variable save filename.txt variable -ascii A(3,2) refers to the element at the third row and the second column of matrix A A([1,3], :) refers to the elements in the first and the third rows of matrix A A(:) put all elements of A into a single column of vector 3. Computing on data .* element multiply by the corresponding element log(v)/exp(v) A' transpose A<3 to judge whether every element of A is less than 3 find(A<3) to find the elements in A that is less than three, turn others to zero sum(a) to sum up a, if put 1 as the second parameter, it will sum up every column and if put 2as the second parameter, it will sumup every row flipud(A) flip up down 4. Plotting data plot(t, y,'r') plot y in red hold on plot on the last figure legend('name') label the line print -dpng 'myplot.png' to save the plot as a file figure(1) switch figures subplot(1,2,1) divide the figure into a 1 by 2 grid and access the first element right now axis([ 0 1 0 1 ]) set the scales of x and y clf clear the figure imagesc(A)take A to plot a grid of colors imagesc(A), colorbar, colormap gray set a gray color map 1.Basic