MATLAB: Is it possible to overload operators on native constructs (cells, structs, etc)?

It is in fact possible to create new operators or overload existing ones for built-in data types in MATLAB. I describe one example of this in my answer to another SO question about modifying the default overflow behavior of integer types. First, you may want to look at what methods currently exist for cell arrays. … Read more

Multi-class classification in libsvm [closed]

According to the official libsvm documentation (Section 7): LIBSVM implements the “one-against-one” approach for multi-class classification. If k is the number of classes, then k(k-1)/2 classifiers are constructed and each one trains data from two classes. In classification we use a voting strategy: each binary classification is considered to be a voting where votes can … Read more

Example of 10-fold SVM classification in MATLAB

Here’s a complete example, using the following functions from the Bioinformatics Toolbox: SVMTRAIN, SVMCLASSIFY, CLASSPERF, CROSSVALIND. load fisheriris %# load iris dataset groups = ismember(species,’setosa’); %# create a two-class problem %# number of cross-validation folds: %# If you have 50 samples, divide them into 10 groups of 5 samples each, %# then train with 9 … Read more

Run Length Encoding in Matlab

Here is a compact solution without loop, cellfun or arrayfun: chainCode=”11012321170701000700000700766666666666665555555544443344444333221322222322″; numCode = chainCode – ‘0’; % turn to numerical array J=find(diff([numCode(1)-1, numCode])); relMat=[numCode(J); diff([J, numel(numCode)+1])];

pdist2 equivalent in MATLAB version 7

Here is vectorized implementation for computing the euclidean distance that is much faster than what you have (even significantly faster than PDIST2 on my machine): D = sqrt( bsxfun(@plus,sum(A.^2,2),sum(B.^2,2)’) – 2*(A*B’) ); It is based on the fact that: ||u-v||^2 = ||u||^2 + ||v||^2 – 2*u.v Consider below a crude comparison between the two methods: … Read more

Call a function by an external application without opening a new instance of Matlab

Based on the not-working, but well thought, idea of @Ilya Kobelevskiy here the final workaround: function pipeConnection(numIterations,inputFile) for i=1:numIterations while(exist(‘inputfile’,’file’)) load inputfile; % read inputfile -> inputdata output = myFunction(inputdata); delete(‘inputfile’); end % Write output to file % Call external application to process output data % generate new inputfile end; Another convenient solution would be … Read more