how do I translate this intruction in matlab?

1 回表示 (過去 30 日間)
Mira le
Mira le 2019 年 11 月 27 日
コメント済み: Mira le 2019 年 11 月 27 日
C={}
C <- C U {S}
W <- W \ {S}

採用された回答

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH 2019 年 11 月 27 日
編集済み: 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
JESUS DAVID ARIZA ROYETH 2019 年 11 月 27 日
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 2019 年 11 月 27 日
can do the same as
S <- S \ S{1} ?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by