Which does NOT return sorted output for a vector of unique values (e.g., v = [3,7,2,5,1])?

Highlights
フォロー


投票は終了しました

投票

Which does NOT return sorted output for a vector of unique values (e.g., v = [3,7,2,5,1])?

sort(v)
8%
unique(v)
16%
union(v, [ ])
17%
intersect(v, v)
14%
setdiff(v, [ ])
12%
All return sorted output
33%
1193 票

サインインして参加する
ganesh
ganesh 2024 年 4 月 1 日
can you give solution oft these problrm
Rik
Rik 2024 年 4 月 2 日

You can try all options yourself and/or read the documentation for each to find the correct answer.

the cyclist
the cyclist 2024 年 3 月 27 日 (編集日時: 2024 年 3 月 27 日)
@goc3 is definitely a unique sort of person.
Rik
Rik 2024 年 3 月 19 日 (編集日時: 2024 年 3 月 19 日)
I don't know about the other functions, but unique used to return the original order (which is probably why the 'stable' switch exists).
I also find it interesting to see the orientation that each of these functions return.
Christian Schröder
Christian Schröder 2024 年 3 月 20 日
Once you know that unique returns sorted output, you can deduce that the last answer should be correct: it would not make sense for only one of the set functions to not return sorted output.
Rik
Rik 2024 年 3 月 21 日
Does it? Because I would also expect the orientation of the resulting vectors to be the same for all set functions, and yet they are not. Can you predict without testing (or reading the documentation) which is the odd one out?
Dyuman Joshi
Dyuman Joshi 2024 年 3 月 22 日 (編集日時: 2024 年 4 月 2 日)
I find it weird that the legacy syntaxes of these (setdiff, intersect and union) mathematical functions are not the same.
Quite inconsistent.
Christian Schröder
Christian Schröder 2024 年 3 月 21 日
Good point, that (orientation of the resulting vectors) is an inconsistency I can't explain. Then again, I only said "should be correct", not "is correct". ;)
goc3
Member of the Community Advisory Board since its inception | MATLAB enthusiast | Code optimizer | Software tester | Materials scientist / mechanical engineer by deg...
23
投稿数s
271
返信数s
16
フォロワー数

タグ

タグが未入力です。

Go to top of page