From a07b61909c0203666b322863661b9fa45b9489cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=28Charybdis=29?= Date: Thu, 14 Dec 2017 18:23:52 +0100 Subject: [PATCH] Fixed bug (substitutions in equations). --- matlab/plot_contributions.m | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/matlab/plot_contributions.m b/matlab/plot_contributions.m index 8b3e5895e..3d0bd14e2 100644 --- a/matlab/plot_contributions.m +++ b/matlab/plot_contributions.m @@ -128,9 +128,24 @@ eval(str) % Replace variables with ds.variablename for i = 1:length(vnames) if ismember(vnames{i}, ds1.name) && ismember(vnames{i}, ds0.name) - regularexpression = ['(([\s\+\-\*/\\^\(])|^)(' vnames{i} ')(([\s\)\+\-\*\/\^])|$)']; - newstring = ['$1ds.' vnames{i} '$3']; - rhs = regexprep(rhs, regularexpression, newstring); + % Match all words with vnames{i} + [b, e] = regexp(rhs, sprintf('\\w*%s\\w*', vnames{i})); + % Filter out non exact matches (words longer than vnames{i}) + rid = find(~(e-b>length(vnames{i}))); + if ~isempty(rid) + b = b(rid); + e = e(rid); + end + % Substitute vnames{i} exact matches by ds.vnames{i} + for j=length(rid):-1:1 + if b(j)>1 && e(j)