Skip to content

Instantly share code, notes, and snippets.

@kmader
Created April 2, 2014 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmader/9937986 to your computer and use it in GitHub Desktop.
Save kmader/9937986 to your computer and use it in GitHub Desktop.
Calculate Alignment from Orientation Data
aligndata=importdata('align_a.csv',',',1)
disp(aligndata.colheaders)
%% parse the data in matlab
% A tiny piece of code to find which column the given header is in
findColumn=@(idstrut,colName) find(not(cellfun('isempty',strfind(idstrut.colheaders,['"' colName '"']))));
% a function to return all of the data in that column
getColumn=@(idstrut,colName) idstrut.data(:,findColumn(idstrut,colName));
%% show the data
figure(1)
subplot(1,2,1);
plot(getColumn(aligndata,'x'),getColumn(aligndata,'y'),'r.')
title('Point Location')
subplot(1,2,2);
xvec=getColumn(aligndata,'xv');
yvec=getColumn(aligndata,'yv');
quiver(zeros(size(xvec)),zeros(size(yvec)),xvec,yvec);% ,'b.')
title('Orientation')
pause(0.5)
%% calculate the alignment tensor
% alignment covariance matrix
acovmat=cov([xvec yvec]);
[eigvecs,eigvals]=eig(acovmat);
eigvals=diag(eigvals);
disp(['Alignment ' num2str((max(eigvals)-min(eigvals))/max(eigvals)*100) '%'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment