Appendix A. Syntax: Quick Reference

In this appendix we offer examples of the MATLAB syntax most commonly used in this book.

Expressions

x = 2 ^ (2 * 3) / 4;
x = A \ b;            % solution of linear equations
a == 0 & b < 0      % a equals 0 AND b less than 0
a ~= 4 | b > 0       % a not equal to 4 OR b greater than 0

Function M-Files

function y=f(x)                              % save as f.m
% comment for help

function [out1, out2] = plonk(in1, in2, in3) % save as plonk.m
% Three input arguments, two outputs
   …

function junk            % no input/output arguments; save as junk.m

[t, x] = ode45(@lorenz, [0 10], x0);  % function handle with @

Graphics

plot(x, y), grid % plots vector y against vector x on a grid plot(x, y, 'b--') % plots a blue dashed line plot(x, y, 'go') % plots green circles plot(y) % if y is ...

Get Essential MATLAB for Engineers and Scientists Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.