vectorNote that this is different to vectormyVec; myVec.reserve(10000);
Sorting a vector and keeping a reverse index
vector<double> myVec = ...; vector<pair<double, int> > sortedVec; sortedVec.reserve(myVec.size()); for (unsigned i = 0; i < myVec.size(); i++) { sortedVec.push_back(make_pair(myVec[i], i)); } sort(sortedVec.begin(), sortedVec.end()); for (unsigned i = 0; i < sortedVec.size(); i++) { assert(myVec[sortedVec[i].second] == sortedVec[i].first); }
Using stl containers
Make sure you define both the assignment operator and copy constructor.
my @myVec = ( ... ); my %reverseIndex = (); @sortedVec = sort { $a <=> $b } @myVec; for (my $i = 0; $i <= $#sortedVec; $i++) { $reverseIndex{$sortedVec[$i]} = $i; }
find . -name "*.cpp" -exec grep -H foo {} \;
Changing the extension of a bunch of files
foreach i (`ls *.oldExt`) mv $i $i:r.newExt end
Using a different version of the compiler to build SVL
make "CCC=g++-4.1"
files = dir([BASEDIR, '/*.jpg']); for i = 1:length(files), disp(['Processing ', files(i).name, '...']); img = imread([BASEDIR, '/', files(i).name]); imagesc(img); pause(1); drawnow; end;
Adding SVL code to the Matlab Path
You can add the STAIR Vision Library to the Matlab path so that you can call SVL scripts and MEX functions from any directory. Once you start Matlab run the command:
run('<BASEDIR>/svl/scripts/addSVLPaths');
where <BASEDIR> is the SVL installation directory.