how do I translate this intruction in matlab?

1 次查看(过去 30 天)
C={}
C <- C U {S}
W <- W \ {S}

采纳的回答

JESUS DAVID ARIZA ROYETH
编辑:JESUS DAVID ARIZA ROYETH 2019-11-27
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 个评论
JESUS DAVID ARIZA ROYETH
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by