MATLAB: How to use intersect(A,B,’legacy’) correctly in the case

intersect

Hello MATLAB community, I am currently using a code from a scientific paper. The code was written with MATLAB 2012b, which means that the behaviour of 'intersect' has changed in newer releases. In order to run the code properly I have to replace all intersect(A,B) by intersect(A,B,'legacy'),according to https://de.mathworks.com/help/matlab/ref/intersect.html . Unfortunately I ran into a problem in this part of the code:
for i=1:N
gvarspecstartemp = [];
for j=1:cstypenum
eval(['starvec.vars{i,j} = intersect(gvarspec.',char(cskeys(i,1)),'.star,endovecfull{j});'])
gvarspecstartemp = [gvarspecstartemp, starvec.vars{i,j}];
end
eval(['gvarspec.',char(cskeys(i,1)),'.star = gvarspecstartemp;'])
end
I do not know how to replace the command in
eval(['starvec.vars{i,j} = intersect(gvarspec.',char(cskeys(i,1)),'.star,endovecfull{j});'])
I already tried these ways:
eval(['starvec.vars{i,j} = intersect(gvarspec.',char(cskeys(i,1)),'.star,endovecfull{j},'legacy');'])
eval(['starvec.vars{i,j} = intersect(gvarspec.',char(cskeys(i,1)),'.star,endovecfull{j},legacy);'])
I would really appreciate your help. Thank you.

Best Answer

I think you want
eval(['starvec.vars{i,j} = intersect(gvarspec.',char(cskeys(i,1)),'.star,endovecfull{j},''legacy'');'])
You need to double the single-quote characters, to tell MATLAB that they are part of the string, not delimiting the string.