Hi all! I have a problem: I create this code to compare strings in Trajectory.mat (attached) and find the longest common sequence. I have used the function at this link http://www.mathworks.com/matlabcentral/fileexchange/24559-longest-common-subsequence
% delete cell of Trajctory that are empty
empties = find(cellfun(@isempty,Trajectory));Trajectory(empties) = [];% Compare strings in Trajectory: find LCS (Longest Common Sequence)
[D, dist, aLongestString] = LCS(Trajectory{1,1},Trajectory{2,1});% Count patterns in LCS
LCS=size(aLongestString,2);% Count patterns in strings that I compare
Q=size(Trajectory{2,1},2);P=size(Trajectory{1,1},2);% Partecipation ratio of the common part to a pattern P
RatioQ = LCS./Q;RatioP = LCS./P;% MSTP-Similarity Equal Aveage
EA=(RatioP + RatioQ)/2;% MSTP-Similarity Weighted Aveage
WA=(P*RatioP+Q*ratioQ)/(P+Q);
The code works right but I want to optimize that: I want to compare all the strings in Trajectory because with this code I have to write a lot of times the same code for every two strings. Can you give me some suggestion to optimize the code and compare all the strings in Trajectory? I try to use a for loop but with disastrous results.
Best Answer