Comparing cell arrays of symbolic variables

조회 수: 7 (최근 30일)
Leo Simon
Leo Simon 2016년 2월 8일
댓글: Walter Roberson 2016년 2월 8일
I'd like to be able to compare two arrays, each consisting of symbolic variables. In particular I'd like to be able to run setdiff on them. But setdiff appears not to work for symbolic arrays, as the example illustrates
syms a b c
G{1} = {a,b,c}
G{2} = {a,b}
setdiff(G{1},G{2})
Is there an alternative way of accomplishing what setdiff should be able to accomplish?
Thanks!

답변 (1개)

Subhadra Mahanti
Subhadra Mahanti 2016년 2월 8일
편집: Subhadra Mahanti 2016년 2월 8일
isequal(G{1},G{2})
The above code will return if true and 0 otherwise.
  댓글 수: 2
Leo Simon
Leo Simon 2016년 2월 8일
Thanks! I actually wanted a command that would return whatever is not in the union of G{1} and G{2}, not just check if they are equal. Obviously setdiff would work if I defined the G's as regular arrays rather than cell arrays, but I need it to works for cells.
Walter Roberson
Walter Roberson 2016년 2월 8일
You do not have symbolic arrays to take the set difference of. {a,b,c} is a cell array each element of which contains one symbol. The symbolic array form would be
G{1} = [a, b, c];

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Number Theory에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by