Rename samples subdirectories

This commit is contained in:
Joshua Peek
2012-07-23 15:52:49 -05:00
parent 314f0e4852
commit 7b6caa0f6c
273 changed files with 2952 additions and 2955 deletions

9
samples/Matlab/average.m Normal file
View File

@@ -0,0 +1,9 @@
function y = average(x)
% AVERAGE Mean of vector elements.
% AVERAGE(X), where X is a vector, is the mean of vector
% elements. Nonvector input results in an error.
[m,n] = size(x);
if (~((m == 1) | (n == 1)) | (m == 1 & n == 1))
error('Input must be a vector')
end
y = sum(x)/length(x);

View File

@@ -0,0 +1,38 @@
function [filtfcn, statefcn] = makeFilter(b, a)
% FILTFCN = MAKEFILTER(B, A) creates an IIR filtering
% function and returns it in the form of a function handle,
% FILTFCN. Each time you call FILTFCN with a new filter
% input value, it computes the corresponding new filter
% output value, updating its internal state vector at the
% same time.
%
% [FILTFCN, STATEFCN] = MAKEFILTER(B, A) also returns a
% function (in the form of a function handle, STATEFCN)
% that can return the filter's internal state. The internal
% state vector is in the form of a transposed direct form
% II delay line.
% Initialize state vector. To keep this example a bit
% simpler, assume that a and b have the same length.
% Also assume that a(1) is 1.
v = zeros(size(a));
filtfcn = @iirFilter;
statefcn = @getState;
function yn = iirFilter(xn)
% Update the state vector
v(1) = v(2) + b(1) * xn;
v(2:end-1) = v(3:end) + b(2:end-1) * xn - ...
a(2:end-1) * v(1);
v(end) = b(end) * xn - a(end) * v(1);
% Output is the first element of the state vector.
yn = v(1);
end
function vOut = getState
vOut = v;
end
end

View File

@@ -0,0 +1,29 @@
classdef matlab_class
properties
R;
G;
B;
end
methods
function obj = matlab_class(r,g,b)
obj.R = r;
obj.G = g;
obj.B = b;
end
function disp(obj)
disp(['Red: ' num2str(obj.R) ...
', Green: ' num2str(obj.G) ...
', Blue: ' num2str(obj.B)]);
end
end
enumeration
red (1,0,0)
green (0,1,0)
blue (0,0,1)
cyan (0,1,1)
magenta (1,0,1)
yellow (1,1,0)
black (0,0,0)
white (1,1,1)
end
end

View File

@@ -0,0 +1,9 @@
function ret = matlab_function(A,B)
% Simple function adding two values and displaying the return value
ret = A+B;
% Display the return value
disp('Return value in function');
disp(ret);

View File

@@ -0,0 +1,12 @@
% Matlab example script
%Call matlab_function function which resides in the same directory
value1 = 5 % semicolon at end of line is not mandatory, only suppresses output to command line.
value2 = 3
% Calculate sum of value1 and value2
result = matlab_function(value1,value2);
disp('called from script')
disp(result);

View File

@@ -0,0 +1,13 @@
% Matlab example script 2
% Comments precended with arbitrary whitespace (spaces or tabs)
%Call matlab_function function which resides in the same directory
value1 = 5 % semicolon at end of line is not mandatory, only suppresses output to command line.
value2 = 3
% Calculate sum of value1 and value2
result = matlab_function(value1,value2);
disp('called from script')
disp(result);