%% Plotting %% Basic plotting commands % The Matlab "plot" command is the basis for most two-dimensional plotting % and visualization tasks in Matlab. If you provide a vector of data, the % plot will index your values as 1, 2, 3, ... y = [1:.5:4].^2 plot(y) %% Specify Domain values % In this example, the domain values are not 1, 2, 3, ... but rather are % spaced by 0.5. Once x is defined, the definition of y can be done in % terms of x. x = [1:.5:4] y = x.^2 %% Plot plot(x, y) %% Another Example and Plotting Options % This example looks at the function % % $$y = x \sin(x^2)$$ % % The @ operator turns an expression in a % variable into a function that takes % the variable as its operand. % NOTE: This is not supported in older versions of Matlab. x = -10:0.001:10; f = @(x) x.*sin(x.^2); y = f(x); plot(x,y); %% Adjust axes axis([-5 5 -4 4]) %% Add a Legend, title, axis labels legend('y = x sin(x^2)') title('My Plot') xlabel('x') ylabel('x sin(x^2)') %% Grid, minor grid, and box around the whole plot grid on grid minor box on