Simple SVM in MATLAB
First to answer your specific questions:


  
  For storing one-dimensional data (arrays), is there usually a preference between column and row matrices?
  


It doesn't matter, use what is most convenient. Often horizontal vectors are used because they are easy to create: 1:10.


  
  Is there an easy way to deal with nested matrices?
  


The best way to collect matrices is using a cell array. A cell array's elements are arbitrary values (matrices, other cell arrays, objects, function handles, whatever you can assign to a variable).


  
  There are a ton of different ways to create matrices, and I'm not sure if the ones I am using are the most appropriate (e.g., via literals, find(), meshgrid(), ones() and zeros(), repmat(), etc.).
  


Yes, MATLAB has a huge library and it is impossible to know if you are using the best possible function in each case. Experience will help.


  
  What is there to do about arbitrary imprecision? For example, I had to put in an arbitrary value threshold to find non-zero values because using find(A &gt; 0) wasn't working. (Since the values were on the magnitude of about 1e-12, this was larger than the value of eps() so that function didn't seem very helpful.)
  


Yes, you need to pick some threshold there. It depends on the source of the data what an appropriate value is. eps is the distance between 1.0 and the next representable floating-point value. That is, there are no possible values in between 1.0 and 1.0+eps. eps is not necessarily an appropriate threshold to find "approximately zero" values.


  
  Naming conventions -- is there one for MATLAB? I don't believe I've seen a consistent style.
  


Not that I know of. Early versions of MATLAB were not case sensitive, so all code was typically written in lower case. Currently some built-in functionality uses an upper case for the first letter, and some use camelCase. There is no PEP8 for MATLAB. :)



Now I'll go through the bits of code that can be improved:


clc;clear all;



Please use the MATLAB Editor, and heeds its warnings. clear all is not useful here, it not only clears variables, it also clears functions from memory. These will need to be read in and parsed again, slowing down your program. clear suffices to remove variables from your workspace.


posDps = data(find(y == 1), :);
negDps = data(find(y == -1), :);



Here you can remove find. The MATLAB Editor also warns about this.

posDps = data(y == 1, :);
negDps = data(y == -1, :);


find is usually not necessary when indexing, only when you need to store an index to an array element.


space = size(data, 2);
n = length(data);



It is always better to specify directly what size you need. length(data) is defined as max(size(data)), I consider this dangerous. Instead:

[n,space] = size(data);


or

space = size(data, 2);
n = size(data, 1);


You should also know numel, which returns the number of elements in a matrix. This is much more efficient than prod(size(data)).


[ y1, y2 ] = meshgrid(y, y);
[ i, j ] = meshgrid(1:n, 1:n);



These are not necessary at all. Since MATLAB R2016b we have implicit singleton expansion, but before that you could use bsxfun to operate on two arrays of different sizes. So none of the following indexing operations are really necessary.


P(i, j) = y1(i, j) .* y2(i, j) .* (data(i,:) * data(j,:)');



can be rewritten as

P = (y .* y.') .* (data * data.');


Note that I use .' here, where you had '. ' is the complex conjugate transpose. Unless you want to compute a dot product, you should avoid it. .' transposes the matrix without changing any of its values. For real-valued data they're the same, but it's good to get used to using the right form, it will prevent difficult to find errors down the road.


Aeq = y';



Same here: y.'.


beq = [ 0 ];



Again, the MATLAB Editor warns here about the useless [] brackets. Heed the warnings!

There is actually no difference in MATLAB between a matrix and a scalar. A scalar is a matrix with a single value. The [...] operator is for concatenation. It concatenates two or more matrices into a single matrix. Every time you have a single matrix inside [], the MATLAB Editor will warn you about it.

Similarly, I often see things like [1:10]. 1:10 is a matrix, the [] don't do anything there.


w = (data' .* repmat(y', [space 1])) * alpha;



Same here: data.', y.'.


svIndices = find(alpha &gt; threshold);
b = y(svIndices(1)) - data(svIndices(1),:) * w;



Here you can use the second argument to find to tell it to give you only one index:

svIndex = find(alpha &gt; threshold,1);
b = y(svIndex) - data(svIndex,:) * w;



domain = (min(data(:,1)) - margin):(max(data(:,1)) + margin);



You don't need this many parentheses here, but they don't hurt either. I actually think they help readability. But the : has a much lower precedence than + and -. This should also work:

domain = min(data(:,1))-margin : max(data(:,1))+margin;