PS1('>> ');
a = 3;
b = 'hi';
a = pi;
disp(sprintf('2 decimanls: %0.2f', a))
format long
format short
A = [ 1 2; 3 4; 5 6]
. This will generate a 3×2 matrix.
v = [1; 2; 3]
w = -6 +sqrt(10)*(randn(1,10000)) hist(w,50)
load featuresX.dat load('featuresX.dat')
A(:,2) = [10; 11; 12] % assuming A is 3xn here
A = [A, [100; 101; 102]]; % Append to the right.
v + ones(length(v),1)
y2=cos(2*i*4*t); plot(t,y2); % This will replace the previous drawing of y1 in the octave figure. % Now to draw both curves: plot(t,y1); hold on; % Tell octave to keep the previous drawing and draw on top of it. plot(t,y2,'r'); % This curve will be in red. xlabel('time') % Set the horizontal axis label. ylabel('value') % Set the vertical axis label. legend('sin','cos') % Add legend for the curves. title('My plot') % Set the title of this figure. cd /cygdrive/w/Temp print -dpng 'myPlot.png' % Save the current figure in a file. close % remove the figure. figure(1); plot(t,y1); % Draw on figure 1 figure(2); plot(t,y2); % Draw on figure 2 subplot(1,2,1); %Divides the plot area in a 1x2 grid and access the first element. plot(t,y1); subplot(1,2,2); plot(t,y2); axis([0.5 1 -1 1]); % Set the range for the axis of the figure. clf; % clear the figure. % trick to display a matrix: A = magic(5) imagesc(A); % Will display the matrix on the figure with multiple colors. imagesc(A), colorbar, colormap gray; % more complex display.
v=zeros(10,1) for i=1:10, v(i) = 2^i; end;
i = 1; while i <= 5, v(i) = 100; i = i+1; end;
i=1; while true, v(i) = 999; i = i+1; if i == 6, break; end; end;
if v(1)==1, disp('The value is one'); elseif v(1) == 2, disp('The value is two'); else disp('The value is something else'); end * To exit octave, we can type **exit** or **quit** === defining functions === * Functions are defined in files with the extension **.m**. * Such a file should contain for instance:<code>function y = squareThisNumber(x) y = x^2;
function [y1, y2] = squareAndCubeThisNumber(x) y1 = x^2; y2 = x^3;
\[ \theta := \theta - \alpha \frac{1}{m} \sum\limits_{i=1}^m (h_\theta(x^{(i)}) - y^{(i)}) x^{(i)} \]