How do I use intersect(A,B,'legacy') correctly in my case?

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.

 Accepted 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.

2 Comments

... but I 100% agree with Stephen's comment on your question.
Thank you very much for your fast response!

Sign in to comment.

More Answers (0)

Tags

Asked:

on 8 Aug 2017

Edited:

on 25 Jun 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!