

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Addition: 2 + 3 Division (using previous answer): ans/ 4 Exponentiation: 31 � 4 Trig functions: log(100); sin(90 � pi/180)
Assigning values: x = [0 : 1 : 5]; x = [7. 5 : 2 : 33] Taking a subset of the vector: x(2 : 5) Assigning a single value: x(4) = x(3) + pi Flipping between row and column vectors: x� Reversing a row vector: flipdim(x, 2) Squaring individual elements: y = x. � 2
Assignment: x = [1 2 3 ; 3 1 2 ; 2 3 1]; x(2, 2) = 6 Math: x/ 4 Exponentiation: x. � 2 Matrix multiplication: x � 2 Extracting vectors: x(1, :); x(:, 1)
2D plots: plot(x, y) Turn on/off plot overlays: hold off; hold on 3D plots: image(x); surf(x); mesh(x) 1
Create a file with the name of your script, ending in .m; e.g., meanvar.m: function [meanval,varval] = meanvar(data) % Computes the mean and variance of values in the data array meanval = mean(data); varval = var(data);
Reading an image: a0 = imread(�c : image.bmp�,�^ bmp�); Displaying an image: image(a0) Assigning a subset of one color: b0 = a0(1 : 445 , 240 : 420 , 2);
Erf function: y = (erf((x − mean)/stdev) + 1) � range/ 2 + offset Computing error of fit: err = sum((double(b0(200, :)) − y). � 2) Minimizing an error function with respect to one variable: q = fminsearch(@(x) sqerferr(x, b0(200, :)), x0)
Looping across all rows of an array: fori = 1 : size(b0, 1) q = fminsearch(@(x) sqerferr(x, b0(i, :)), x0); stdev0(i) = q(2); end 2