MATLAB Answers

how do I translate this intruction in matlab?

1 view (last 30 days)
C={}
C <- C U {S}
W <- W \ {S}

  0 Comments

Sign in to comment.

Accepted Answer

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH on 27 Nov 2019
Edited: JESUS DAVID ARIZA ROYETH on 27 Nov 2019
solution:
S=3;%any value of S
W=[1 2 3 4 8]; %aný value of W
C=[];%C={}
C(end+1)=S%C <- C U {S}
W=setdiff(W,S)%W <- W \ {S}
EDIT:
with cells you can do it like that, but if you are going to work with numbers I recommend working with matrices:
S={3};%any value of S
W={1 2 3 4 8}; %aný value of W
C={};%C={}
C(end+1)=S%C <- C U {S}
for k=1:numel(S)
W(cellfun(@(x,y) isequal(x,S{k}),W))=[]%W <- W \ {S}
end

  3 Comments

Mira le
Mira le on 27 Nov 2019
it doesn't work with cell? w = {1 2 } and S also is cell S={}
JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH on 27 Nov 2019
here:
S={3};%any value of S
W={1 2 3 4 8}; %aný value of W
C={};%C={}
C(end+1)=S%C <- C U {S}
for k=1:numel(S)
W(cellfun(@(x,y) isequal(x,S{k}),W))=[]%W <- W \ {S}
end
Mira le
Mira le on 27 Nov 2019
can do the same as
S <- S \ S{1} ?

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!